PHP list () function
Examples
The values in the array is assigned to a number of variables:
<?php
$my_array = array("Dog","Cat","Horse");
list($a, $b, $c) = $my_array;
echo "I have several animals, a $a, a $b and a $c.";
?>
$my_array = array("Dog","Cat","Horse");
list($a, $b, $c) = $my_array;
echo "I have several animals, a $a, a $b and a $c.";
?>
Running instance »
Definition and Usage
list () function is used in a single operation to a group variable.
Note: This function is only used numerically indexed arrays.
grammar
list( var1,var2... )
参数 | 描述 |
---|---|
var1 | 必需。第一个需要赋值的变量。 |
var2,... | 可选。更多需要赋值的变量。 |
technical details
return value: | Returns the assigned array. |
---|---|
PHP version: | 4+ |
More examples
Example 1
Use the first and third variables:
<?php
$my_array = array("Dog","Cat","Horse");
list($a, , $c) = $my_array;
echo "Here I only use the $a and $c variables.";
?>
$my_array = array("Dog","Cat","Horse");
list($a, , $c) = $my_array;
echo "Here I only use the $a and $c variables.";
?>
Running instance »
Complete PHP Array Reference