Today in the development of a method to see the list language structure, just beginning to think it is a function in PHP!
List () is used to assign values to a set of variables in a single operation.
Note: List () is used only for arrays of numeric indexes and assumes that the numeric index starts at 0.
Description
List () assigns a value to a set of variables using the elements in the array.
Note that, like array (), list () is actually a language structure, not a function.
Such as:
<?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 results are as follows and can be output normally
650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/1043589/201611/ 1043589-20161118144822779-1169439759.png "/>
When an array is not a numeric array but an associative array, such as:
<?php
$my _array = Array (' a ' = = ' Dog ', ' b ' = ' Cat ', ' c ' = ' Horse ');
List ($a, $b, $c) = $my _array;
Echo ' I have several animals, a '. $a. ', a '. $b. ' and a '. $c;
?>
The result will be an error.
650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/1043589/201611/ 1043589-20161118145321185-1621094066.png "/>
When using an indexed array is as follows:
<?php
$my _array = Array (0=> ' Dog ',1=> ' Cat ',2=> ' Horse ');
List ($a, $b, $c) = $my _array;
Echo ' I have several animals, a '. $a. ', a '. $b. ' and a '. $c;
?>
This is a normal output when the code is changed to
<?php
$my _array = Array (1=> ' Dog ',2=> ' Cat ',3=> ' Horse ');
List ($a, $b, $c) = $my _array;
Echo ' I have several animals, a '. $a. ', a '. $b. ' and a '. $c;
?>
The output is as follows
650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/1043589/201611/ 1043589-20161118150139138-2090392627.png "/>
The list function in PHP