listAssign variables as if they were an array
&reftitle.description;
arraylistmixedvar1mixed...
Like array, this is not really a function,
but a language construct. list is used to
assign a list of variables in one operation.
list only works on numerical arrays and assumes
the numerical indices start at 0.
In PHP 5, list assigns the values starting with the
right-most parameter. In PHP 7, list starts with the
left-most parameter.
If you are using plain variables, you don't have to worry about this. But
if you are using arrays with indices you usually expect the order of the
indices in the array the same you wrote in the list
from left to right, which is not the case in PHP 5, as it's assigned in the
reverse order.
Generally speaking, it is advisable to avoid relying on a specific order
of operation, as this may change again in the future.
Modification of the array during list execution (e.g.
using list($a, $b) = $b) results in undefined behavior.
&reftitle.parameters;
var1
A variable.
&reftitle.returnvalues;
Returns the assigned array.
&reftitle.changelog;
&Version;&Description;7.0.0
The order that the assignment operations are performed in has
changed.
7.0.0list expressions can no longer be completely
empty.
7.0.0
Strings can no longer be unpacked.
&reftitle.examples;
list examples
]]>
An example use of list
Employee name
Salary
query("SELECT id, name, salary FROM employees");
while (list($id, $name, $salary) = $result->fetch(PDO::FETCH_NUM)) {
echo "
\n";
}
?>
]]>
Using nested list
]]>
Using list with array indices
]]>
Gives the following output (note the order of the elements compared in
which order they were written in the list syntax):
&example.outputs.7;
string(6) "coffee"
[1]=>
string(5) "brown"
[2]=>
string(8) "caffeine"
}
]]>
&example.outputs.5;
string(8) "caffeine"
[1]=>
string(5) "brown"
[0]=>
string(6) "coffee"
}
]]>
list and order of index definitions
The order in which the indices of the array to be consumed by
list are defined is irrelevant.
'a', 'foo' => 'b', 0 => 'c');
$foo[1] = 'd';
list($x, $y, $z) = $foo;
var_dump($foo, $x, $y, $z);
]]>
Gives the following output (note the order of the elements compared in
which order they were written in the list syntax):
string(1) "a"
["foo"]=>
string(1) "b"
[0]=>
string(1) "c"
[1]=>
string(1) "d"
}
string(1) "c"
string(1) "d"
string(1) "a"
]]>
&reftitle.seealso;
eacharrayextract