Open
Description
Description
The following code:
<?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);
Resulted in this output:
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
But I expected this output instead:
Array
(
[0] => 1
[a] => 2
[1] => 3
[b] => 4
)
Array
(
[0] => 1
[a] => 2
[1] => 3
[b] => 4
)
PHP Version
PHP 8.0 and higher