3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = [ "one" => "one", "two" => "two", "group1" => [ "three" => "three", "four" => "four", "group2" => [ "five" => "five", ], ], "group3" => [ "six" => "six", ] ]; function mergeRecursive(array $array, $result = []) { foreach($array as $k => $v) { if(!is_array($array)) $result[] = $v; else $result[] = $k . mergeRecursive($v); } return $result; } $result = mergeRecursive($arr); print_r($result);
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.6
Fatal error: Uncaught TypeError: mergeRecursive(): Argument #1 ($array) must be of type array, string given, called in /in/uFbFK on line 27 and defined in /in/uFbFK:22 Stack trace: #0 /in/uFbFK(27): mergeRecursive('one') #1 /in/uFbFK(35): mergeRecursive(Array) #2 {main} thrown in /in/uFbFK on line 22
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Fatal error: Uncaught TypeError: Argument 1 passed to mergeRecursive() must be of the type array, string given, called in /in/uFbFK on line 27 and defined in /in/uFbFK:22 Stack trace: #0 /in/uFbFK(27): mergeRecursive('one') #1 /in/uFbFK(35): mergeRecursive(Array) #2 {main} thrown in /in/uFbFK on line 22
Process exited with code 255.
Output for 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.28
Catchable fatal error: Argument 1 passed to mergeRecursive() must be of the type array, string given, called in /in/uFbFK on line 27 and defined in /in/uFbFK on line 22
Process exited with code 255.

preferences:
170.1 ms | 402 KiB | 243 Q