PHP list () assigns the values in the array to a simple instance of the variable, list Array
List ()
PHP list () assigns values in the array to some variables with one-step operations. Like array (), list () is not a real function, but a language structure.
Syntax:
Void list (mixed var, mixed...) Note: list () can only be used as an array of numeric indexes and assume that the numeric index starts from 0.
Example 1:
<? Php $ arr_age = array (18, 20, 25); list ($ wang, $ li, $ zhang) = $ arr_age; echo $ wang; // output: 18 echo $ zhang; // output: 25?>
Example 2: Data Table query:
$ Result = mysql_query ("SELECT id, username, email FROM user", $ conn); while (list ($ id, $ username, $ email) = mysql_fetch_row ($ result )) {echo "username: $ username <br/>"; echo "email: $ email ";}
List () using array Indexes
In list (), you can use another array to receive values assigned to an array. However, when an indexed array is used, the order of values is the opposite of the order listed in list:
$ Arr_age = array (18, 20, 25 );
List ($ a [0], $ a [1], $ a [2]) = $ arr_age;
Print_r ($ a); the output $ a array structure is as follows:
Array ([2] => 25 [1] => 20 [0] => 18)
In the above PHP list (), the simple example of assigning the values in the array to the variables is all the content shared by the small editor. I hope to give you a reference, and I hope you can support the help house a lot.