<?php $array = [ "arr1" => [1, 2, 3, 4], "arr2" => ["a", "b", "c", "d"] ]; $start = microtime(1); foreach ($array as $arr) { foreach ($arr as $a) { echo $a; } } $first = microtime(1) - $start; $start = microtime(1); $all = array_merge($array["arr1"], $array["arr2"]); foreach ($all as $a) { echo $a; } $second = microtime(1) - $start; $start = microtime(1); function test_print($item, $key) { echo $item; } array_walk_recursive($array, 'test_print'); $third = microtime(1) - $start; $start = microtime(1); function loop($array){ foreach($array as $value){ if(is_array($value)){ loop($value); }else{ echo $value; } } } loop($array); $fourth = microtime(1) - $start; echo "\n\n"; echo "Nested: " . $first*1000 . "\n" . "array_merge: " . $second*1000 . "\n" . "array_walk_recursive: " . $third*1000 . "\n" . "Recursive function: " . $fourth*1000;
You have javascript disabled. You will not be able to edit any code.