# Specifying Keys in `list()`

> 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/specifying-keys-in-list/>

Prior to PHP 7.1, the `list()` statement for unpacking array elements into variables only supported arrays with numbered keys starting from zero.

PHP 7.1 adds the ability to specify keys when unpacking array elements into variables. In the example shown below, we first construct an array with the keys `first`, `second`, and `third`. We then unpack this array and store the value of `$data['first']` in the variable `$a`, the value of `$data['second']` in the variable `$b`, and the value of `$data['third']` in the variable `$c`:

``` php
$data = [
    'first'  => 'foo',
    'second' => 'bar',
    'third'  => 'barbara'
];

[
    'first'  => $a,
    'second' => $b,
    'third'  => $c
] = $data;

var_dump($a, $b, $c);
```

Executing the example shown above with PHP 7.1 will print the output shown below:

    string(3) "foo"
    string(3) "bar"
    string(7) "barbara"

Any expression, including constants and variables, can be used to specify a key.

---

Previous: [list() and the ArrayAccess Interface](https://php7explained.com/new-and-extended-functionality/arrays/list-and-the-arrayaccess-interface/index.html.md) | Next: [list() and References](https://php7explained.com/new-and-extended-functionality/arrays/list-and-references/index.html.md)
