Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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

PHP Error Messages

PHP Features

Last updated: 09 November 2026