$ele) { $tmp[] = $ele; } } function WhileListEachLoopWithKey() { global $test_array; while (list($k, $ele) = each($test_array)) { $tmp[] = $ele; } } function GetKeyLoop() { global $test_array; $keys = array_keys($test_array); $count = sizeOf($keys); for ($i=0; $i<$count; $i++) { $tmp[] = $test_array[$keys[$i]]; } } $tests = array( 'ForEachLoop', 'WhileListEachLoop', 'ForEachLoopWithKey', 'WhileListEachLoopWithKey', 'GetKeyLoop' ); $test_score = array(); foreach ($tests as $test) { // Foreach test for ($a=1; $a<=5; $a++) { reset($test_array); $timestart = microtime_float(); call_user_func($test); $time_took = microtime_float() - $timestart; $test_score[$test][] = $time_took*1000; } } ?>
Loop style Test 1 Test 2 Test 3 Test 4 Test 5 Average