- uniqid: documentation ( source)
- microtime: documentation ( source)
- array_fill: documentation ( source)
- printf: documentation ( source)
<?php
$array = array_fill(0, 100, uniqid('', false));
$array2 = $array;
$timer = microtime(true);
$k = $j = 0;
for ($i = 0; $i < 10; $i++) {
while (list($key, $value) = each($array)) {
$j++;
}
}
printf("While list each %.3f sec\n", microtime(true) - $timer);
echo $j . ' iterations' . PHP_EOL;;
$timer = microtime(true);
for ($i = 0; $i < 10; $i++) {
foreach ($array2 as $key => &$value) {
$k++;
}
}
printf("Foreach %.3f sec\n", microtime(true) - $timer);
echo $k . ' iterations' . PHP_EOL;;