Skip to content

Instantly share code, notes, and snippets.

@waylandzhang
Last active December 25, 2015 20:59
Show Gist options
  • Save waylandzhang/7038924 to your computer and use it in GitHub Desktop.
Save waylandzhang/7038924 to your computer and use it in GitHub Desktop.
Frequently Used Functions
<?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