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 equalvar_dump($array1 == $array2, $array1 == $array3, $array1 == $array4);// Test function 1function array_walk_list_each(&$array, $function, $userData = null) { while ( list($key, $value) = each($array) ) $function($array[$key], $key, $userData);}// Test function 2function array_walk_foreach1(&$array, $function, $userData = null) { foreach ($array as $key => &$value ) $function($value, $key, $userData);}// Test function 3function 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;}
Output for hhvm-3.10.0

Process exited with code 153.
Output for 5.4.0 - 5.4.32
<?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 equalvar_dump($array1 == $array2, $array1 == $array3, $array1 == $array4);// Test function 1function array_walk_list_each(&$array, $function, $userData = null) { while ( list($key, $value) = each($array) ) $function($array[$key], $key, $userData);}// Test function 2function array_walk_foreach1(&$array, $function, $userData = null) { foreach ($array as $key => &$value ) $function($value, $key, $userData);}// Test function 3function 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;}