Skip to content

Instantly share code, notes, and snippets.

@oppara
Created May 23, 2011 14:21
Show Gist options
  • Save oppara/986771 to your computer and use it in GitHub Desktop.
Save oppara/986771 to your computer and use it in GitHub Desktop.
<?php
// array_change_key_case.php
$cnt = 1000;
$ret = array();
$array = makeAssoc($cnt);
while ($cnt--) {
$ret = array_change_key_case($array);
}
// foreach.php
$cnt = 1000;
$ret = array();
$array = makeAssoc($cnt);
while ($cnt--) {
foreach ($array as $k => $v) {
$k = strtolower($k);
$ret[$k] = $v;
}
}
// common func
function makeAssoc($cnt) {
$ret = array();
$i = $cnt;
while ($i--) {
$key = getRandomString();
$ret[$key] = $key;
}
return $ret;
}
// http://www.ecoop.net/memo/2005-05-31-1.html
function getRandomString($len = 8) {
$char_list = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_';
mt_srand();
$res = '';
for ($i = 0; $i < $len; $i++) {
$res .= $char_list {
mt_rand(0, strlen($char_list) - 1)
};
}
return $res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment