list
Assign variables as if they were an array
Description
voidlist
mixedvarname
mixed...
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.
list examples
]]>
An example use of list
Employee name |
Salary |
\n" .
" $name | \n" .
" $salary | \n" .
" \n";
}
?>
]]>
list assigns the values starting with the right-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 it isn't. It's
assigned in the reverse order.
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):
string(8) "caffeine"
[1]=>
string(5) "brown"
[0]=>
string(6) "coffee"
}
]]>
See also each, array
and extract.