3v4l.org

run code in 500+ PHP versions simultaneously
<?php function array_push_cust(&$arr, ...$args) { foreach ($args as $k => $v) { if (is_int($k)) { $arr[] = $v; } else { $arr[$k] = $v; } } } $arr = [1, 'a' => 2]; $arr2 = [3, 'b' => 4]; $res = $arr; array_push_cust($res, ...$arr2); print_r($res); $res = $arr; array_push($res, ...$arr2); print_r($res);
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.32, 8.3.0 - 8.3.33, 8.4.1 - 8.4.24, 8.5.0 - 8.5.9
Array ( [0] => 1 [a] => 2 [1] => 3 [b] => 4 ) Fatal error: Uncaught ArgumentCountError: array_push() does not accept unknown named parameters in /in/0p5Sv:21 Stack trace: #0 /in/0p5Sv(21): array_push(Array, 3, b: 4) #1 {main} thrown in /in/0p5Sv on line 21
Process exited with code 255.
Output for 7.4.33
Fatal error: Uncaught Error: Cannot unpack array with string keys in /in/0p5Sv:17 Stack trace: #0 {main} thrown in /in/0p5Sv on line 17
Process exited with code 255.

preferences:
88.24 ms | 1194 KiB | 4 Q