void list (mixed varname, mixed ...)
Note: List () can only be used for arrays of numeric indices and assumes that the numeric index starts at 0
Example
code is as follows |
copy code |
. PHP $info = array (' coffee ', ' brown ', ' caffeine '); //Listing All of the Variables list ($drink, $color, $power) = $info; Echo $drink is $color and $power makes it s PECIAL.N "; //Listing Some of them list ($drink, $power) = $info; Echo $drink has $power. N "; //Let's skip to only the third one list (,, $power) = $info; echo "I need $power!n"; //List () doesn ' t work with strings List ($bar) = "ABCDE"; Var_dump ($bar);//NULL ? |
The each () function generates an array of key names and key values of the elements that the array's current internal pointer points to, and moves the internal pointer forward.
Array each (array &array)
Returns the key/value pair of the current pointer position in array arrays and moves the array pointer forward. A key-value pair is returned as an array of four cells, with the key named 0,1,key and value. The unit 0 and key contain the key names of the array cells, and 1 and value contain the data.
The code is as follows |
Copy Code |
? $people = Array ("Peter", "Joe", "Glenn", "Cleveland"); Print_r (each ($people)); ?> |
Each () is used in conjunction with the list () to traverse the array.
For example:
code is as follows |
copy code |
<?php $cities =array ("California" =>array ("Martinez", "San Francisco", "Los Angeles"), "New York" =>array ("New York", "Buffalo") ); while (list ($key, $value) =each ($cities) { //echo $key; //echo "Fdash"; //echo while (list ($key 0, $val) =each ($value)) { echo elements: $key 0,value: $val <br>n "; } } |