3v4l.org

run code in 300+ PHP versions simultaneously
<?php $elements = array(); //// // An array of 10,000 elements with random string values //// for($i = 0; $i < 10000; $i++) { $elements[] = [(string)rand(10000000, 99999999)]; } $time_start = microtime(true); //// // for test //// $numb = count($elements); for($i = 0; $i < $numb; $i++) { $elements[$i][0] = 1; } $time_end = microtime(true); $for_time = $time_end - $time_start; $time_start = microtime(true); //// // for with count() inside loop test //// for($i = 0; $i < count($elements); $i++) { $elements[$i][0] = 1; } $time_end = microtime(true); $for_count_time = $time_end - $time_start; $time_start = microtime(true); //// // foreach test //// foreach($elements as &$element) { $element[0]= 1; } $time_end = microtime(true); $foreach_time = $time_end - $time_start; echo "For took: " . number_format($for_time * 1000, 3) . "ms\n"; echo "For with count() took: " . number_format($for_count_time * 1000, 3) . "ms\n"; echo "Foreach took: " . number_format($foreach_time * 1000, 3) . "ms\n";

preferences:
36.11 ms | 402 KiB | 5 Q