# Spread Operator in Array Expressions

> Section in “New and Extended Functionality › Arrays” of the book [PHP 7 Explained](https://php7explained.com/) by Sebastian Bergmann and Stefan Priebsch, published by thePHP.cc. The book covers PHP 7.0 to 7.4 and was last updated in November 2020. HTML version: <https://php7explained.com/new-and-extended-functionality/arrays/spread-operator-in-array-expressions/>

The spread operator `...`, used to unpack arguments, has already been introduced in PHP 5.6:

``` php
var_dump(...[1, 2, 3]);
```

It converts an array to a list of elements:

    int(1)
    int(2)
    int(3)

The upside of argument unpacking is that instead of passing around an untyped array, you can add a type declaration and thus make sure all passed arguments have the same type.

Since PHP 7.4, the so-called splat operator can directly be used inside arrays:

``` php
$list = [3, 4, 5];

var_dump([1, 2, ...$list, 6]);
```

This will output:

    array(6) {
      [0] => int(1)
      [1] => int(2)
      [2] => int(3)
      [3] => int(4)
      [4] => int(5)
      [5] => int(6)
    }

There are two limitations that you need to be aware of. First, arrays cannot be assoiative, they must be index-based. Second, you cannot unpack an array by reference:

``` php
$list = [3, 4, 5];

var_dump(...&$list);
```

Trying to use a reference operator directly leads to a syntax error:

    PHP Parse error:  syntax error, unexpected '&' in ...

---

Previous: [array_key_first() and array_key_last()](https://php7explained.com/new-and-extended-functionality/arrays/array_key_first-and-array_key_last/index.html.md) | Next: [Mathematics](https://php7explained.com/new-and-extended-functionality/mathematics/index.html.md)
