3v4l.org

run code in 300+ PHP versions simultaneously
<?php $fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple"); function test_alter(&$item1, $key, $prefix) { $item1 = "$prefix: $item1"; } function test_print($item2, $key) { echo "$key. $item2<br />\n"; } echo "Before ...:\n"; array_walk($fruits, 'test_print'); // array_walk($fruits, 'test_alter', 'fruit'); echo "... and after:\n"; array_walk($fruits,function(&$value, &$key){$key = $value; $value=false;}); var_dump($fruits);
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Before ...: d. lemon<br /> a. orange<br /> b. banana<br /> c. apple<br /> ... and after: Warning: {closure}(): Argument #2 ($key) must be passed by reference, value given in /in/ER2rG on line 21 Warning: {closure}(): Argument #2 ($key) must be passed by reference, value given in /in/ER2rG on line 21 Warning: {closure}(): Argument #2 ($key) must be passed by reference, value given in /in/ER2rG on line 21 Warning: {closure}(): Argument #2 ($key) must be passed by reference, value given in /in/ER2rG on line 21 array(4) { ["d"]=> bool(false) ["a"]=> bool(false) ["b"]=> bool(false) ["c"]=> bool(false) }
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Before ...: d. lemon<br /> a. orange<br /> b. banana<br /> c. apple<br /> ... and after: Warning: {closure}(): Argument #2 ($key) must be passed by reference, value given in /in/ER2rG on line 21 Warning: {closure}(): Argument #2 ($key) must be passed by reference, value given in /in/ER2rG on line 21 Warning: {closure}(): Argument #2 ($key) must be passed by reference, value given in /in/ER2rG on line 21 Warning: {closure}(): Argument #2 ($key) must be passed by reference, value given in /in/ER2rG on line 21 array(4) { ["d"]=> bool(false) ["a"]=> bool(false) ["b"]=> bool(false) ["c"]=> bool(false) }
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.5 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33
Before ...: d. lemon<br /> a. orange<br /> b. banana<br /> c. apple<br /> ... and after: array(4) { ["d"]=> bool(false) ["a"]=> bool(false) ["b"]=> bool(false) ["c"]=> bool(false) }

preferences:
155.03 ms | 402 KiB | 172 Q