3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php // Test results $array1 = test('array_walk'); $array2 = test('array_walk_list_each'); $array3 = test('array_walk_foreach1'); $array4 = test('array_walk_foreach2'); // Check arrays for equal var_dump($array1 == $array2, $array1 == $array3, $array1 == $array4); // Test function 1 function array_walk_list_each(&$array, $function, $userData = null) { while ( list($key, $value) = each($array) ) $function($array[$key], $key, $userData); } // Test function 2 function array_walk_foreach1(&$array, $function, $userData = null) { foreach ($array as $key => &$value ) $function($value, $key, $userData); } // Test function 3 function array_walk_foreach2(&$array, $function, $userData = null) { foreach ($array as $key => $value ) $function($array[$key], $key, $userData); } function some_function(&$value, $key, $userData) { $value = "$key => $userData"; } function test($function, $count = 10000, $arrayElements = 1000) { echo $function, ' ... '; $array = array_fill(0, $arrayElements, "some text value"); $timer = microtime(true); for( $i = 0; ++$i < $count; ) $function($array, 'some_function', 'some user data'); printf("%.3f sec\n", microtime(true) - $timer); return $array; }
based on E9Tum
Output for 7.1.0
array_walk ... 1.178 sec array_walk_list_each ... -0.002 sec array_walk_foreach1 ...
Process exited with code 137.
Output for 7.0.14
array_walk ... 1.059 sec array_walk_list_each ... 0.002 sec array_walk_foreach1 ... 1.079 sec array_walk_foreach2 ...
Process exited with code 137.
Output for 7.0.6
array_walk ... 0.979 sec array_walk_list_each ... 0.001 sec array_walk_foreach1 ... 1.130 sec array_walk_foreach2 ...
Process exited with code 137.
Output for 7.0.5
array_walk ... 0.965 sec array_walk_list_each ... 0.001 sec array_walk_foreach1 ... 1.159 sec array_walk_foreach2 ...
Process exited with code 137.
Output for 7.0.4
array_walk ... 0.944 sec array_walk_list_each ... 0.001 sec array_walk_foreach1 ... 1.211 sec array_walk_foreach2 ...
Process exited with code 137.
Output for 7.0.3
array_walk ... 1.029 sec array_walk_list_each ... 0.001 sec array_walk_foreach1 ... 1.185 sec array_walk_foreach2 ...
Process exited with code 137.
Output for 7.0.2
array_walk ... 0.950 sec array_walk_list_each ... 0.001 sec array_walk_foreach1 ... 1.176 sec array_walk_foreach2 ...
Process exited with code 137.
Output for 7.0.1
array_walk ... 0.973 sec array_walk_list_each ... 0.001 sec array_walk_foreach1 ... 1.150 sec array_walk_foreach2 ...
Process exited with code 137.
Output for 7.0.0
array_walk ... 0.960 sec array_walk_list_each ... 0.001 sec array_walk_foreach1 ... 1.208 sec array_walk_foreach2 ...
Process exited with code 137.
Output for 5.0.0 - 5.6.28
array_walk ...
Process exited with code 137.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected '&', expecting T_VARIABLE or '$' in /in/F5oG9 on line 20
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected '&', expecting T_VARIABLE or '$' in /in/F5oG9 on line 20
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_VARIABLE' or `'$'' in /in/F5oG9 on line 20
Process exited with code 255.