|
| USING THE list() FUNCTION ON PHP ARRAYS
The list() function allows you to retrieve several values at once from an array. The list() function copies values from the array into variables you specify.
Suppose you have this array:
$colors=array('blue', 'red', 'green');
Say you want to list the first two values of this array, you do:
list($firstValue, $secondValue) = $colors;
The list function creates two variables named $firstValue and $secondValue and stores the first and second values of the array in them consecutively.
echo $firstValue; // outputs blue
echo $secondValue; // outputs red
The above feature is equivalent to:
$firstValue = $colors[0];
$secondValue = $colors[1];
echo $firstValue; // outputs blue
echo $secondValue; // outputs red
See also:
|
|