Unpacking A Single Element Array¶
<?php
function foo() {
print_r(func_get_args());
}
$array = [1,2,3];
// Not possible
// cannot use positional argument after unpacking
//foo(...$array, ...$array, 4);
foo(...$array, ...$array, ...[4]);
The ellipsis operator ... is used to unpack arrays as individual arguments in a method call. Its opposite is the [] array, which holds a random number of values.
Using both together is useless, as ellipsis neutralize the array.
Yet, when unpacking several arrays as arguments, it is not possible to use literal values after the unpacked arguments.
The solution is to put these arguments in another literal array, and unpack them, as the previous ones.
See Also¶
Unpacking single element arrays [Try me]
PHP Error Messages¶
PHP Features¶
Last updated: 14 July 2026