使用 list() 解構陣列
使用 list()
快速將變數值列表分配到陣列中。另見 compact()
// Assigns to $a, $b and $c the values of their respective array elements in $array with keys numbered from zero
list($a, $b, $c) = $array;
使用 PHP 7.1(目前處於測試階段),你將能夠使用短列表語法 :
// Assigns to $a, $b and $c the values of their respective array elements in $array with keys numbered from zero
[$a, $b, $c] = $array;
// Assigns to $a, $b and $c the values of the array elements in $array with the keys "a", "b" and "c", respectively
["a" => $a, "b" => $b, "c" => $c] = $array;