3v4l.org

run code in 300+ PHP versions simultaneously
<?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;;
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.8
While list each 0.000 sec 100 iterations Foreach 0.000 sec 1000 iterations

preferences:
48.4 ms | 406 KiB | 5 Q