Ellipsis With Array Parameters

<?php

function foo($a, $b) { echo "$a $b
";}

foo(...['x', 'y']);                 // x y
// named parameters
foo(...['a' => 'x',  'b' => 'y']);  // x y
foo(...['b' => 'x',  'a' => 'y']);  // y x

// positional parameters: integer key not used
foo(...[0 => 'x',  1 => 'y']);      // x y
foo(...[120 => 'x',  11 => 'y']);   // x y
foo(...[11 => 'y', 120 => 'x']);    // y x

?>

It is possible to spread parameters from an array, when calling a function.

With string keys, the parameters are named and assigned their corresponding parameter.

With integer positions, the parameters are used depending of their position in the array, not their actual key.

It might require a call to ksort() or array_values() to make it clear.

See Also

PHP Features

Last updated: 14 July 2026