List

List() acts as the contrary to array() : it will break an array into individual elements, and assign them to the arguments of the list.

List() also has a short array version, which is [ ] the square brackets. Those square brackets are only appearing on the left side of an assignation.

list() may omit extracted values by skipping their value, and leaving seemingly empty arguments. List() also supports double-arrow notation, where the key is provided.

list() may be nested. It may also be used with foreach() structures.

list() looks like a function, though it is the only one to appears on the left part of an assignation, and is actually a language-construct.

A list is also the name given to arrays where the index are the automatic ones.

<?php

list($a, $b, $c) = [1,2,3];

[$a, , [$c]] = [1,2,[3],4];

[2 => $c, 0 => $a] = [1,2,3,4];

$rows = [[1,2], [3, 4]];
foreach($rows as [$a, $b]) {
    print "$a + $b\n";
}

// Only values are important here
$list = range(10, 12);

// some keys are missing => not a list
$array = array(10, 4 => 12);

?>

Documentation

See also List-o-mania

Related : Array