Last active
December 25, 2015 20:59
-
-
Save waylandzhang/7038924 to your computer and use it in GitHub Desktop.
Frequently Used Functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// used in simpledb return values from AWS SDK2 | |
function array_push_associative(&$arr) { | |
$args = func_get_args(); | |
array_unshift($args); // remove &$arr argument | |
foreach ($args as $arg) { | |
if (is_array($arg)) { | |
foreach ($arg as $key => $value) { | |
$arr[$key] = $value; | |
$ret++; | |
} | |
} | |
} | |
return $ret; | |
} | |
// Used in simpledb return values from AWS SDK3 | |
function attrToArray($attr){ | |
$array = array(); | |
foreach ($attr as $key => $value) { | |
if(empty($value['Value']) && $value['Value'] != '0'){ | |
$value_Value = ''; | |
}else{ | |
$value_Value = $value['Value']; | |
} | |
$array = $array + array($value['Name']=>$value_Value); | |
} | |
return $array; | |
} | |
// generate random CODE | |
function generateToken() { | |
$length = 9; | |
$characters = '0123456789abcdefghijklmnopqrstuvwxyz'; | |
$string = ''; | |
for ($p = 0; $p < $length; $p++) { | |
$string .= $characters[mt_rand(0, strlen($characters))]; | |
} | |
return $string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment