- substr: documentation ( source)
- microtime: documentation ( source)
- str_shuffle: documentation ( source)
- round: documentation ( source)
<?php
function getRandomStr($length){
return substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $length);
}
$start = microtime(true);
// Mixed could theoretically be an object or an array.
// In this example it's an array.
$mixed = array();
for($i = 0; $i < 100; $i++) {
if (is_array($mixed)) {
$mixed[getRandomStr(15)] = 'abcd';
} else {
// Do something else which we don't care about here
}
}
print round(microtime(true) - $start, 2) . 's';