Assign the values in the array to some 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.";?>The list() function is used to assign values to a set of variables in one operation.
Note: This function only works with numerically indexed arrays.
list( var1,var2... )
parameter | describe |
---|---|
var1 | Required. The first variable to be assigned a value. |
var2,... | Optional. More variables need to be assigned values. |
Return value: | Returns the assigned array. |
---|---|
PHP version: | 4+ |
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."; ?>