3v4l.org

run code in 300+ PHP versions simultaneously
<?php // The test considers that the array may be associative $arrayExample = array_fill(0, 1000, 'hello'); $testsCount = 1000; $start = microtime(true); for ($i = 0; $i < $testsCount; ++$i) { $array = array_reverse($arrayExample); foreach ($array as $value) { // } } printf("array_reverse: %fs\n", microtime(true) - $start); $start = microtime(true); for ($i = 0; $i < $testsCount; ++$i) { $array = array_values($arrayExample); for ($j = count($array) - 1; $j >= 0; --$j) { $value = $array[$j]; } } printf("array_values %fs\n", microtime(true) - $start); $start = microtime(true); for ($i = 0; $i < $testsCount; ++$i) { $array = $arrayExample; while ($array) { $value = array_pop($array); } } printf("array_pop: %fs\n", microtime(true) - $start);

preferences:
27.96 ms | 410 KiB | 5 Q