. While traversal
In each loop of the while () statement, each () statement assigns the key of the current array element to the first argument variable $key of the list () function. and assigns the value in the current array element to the second parameter variable $value in the list () function, and each () statement then moves the pointer inside the array one step back, so that the next time () statement loops, it gets the key/value pair for the next element in the array. Until the end of the array each () statement returns the False,while () statement to stop the loop, ending the traversal of the array.
<body><?PHP//each () function takes an array of element information that the current pointer points to, and returns an array with key-value pairs, one at a time, once for each execution .$arr=Array(1=> "AA",2=> "BB",3=> "CC",4=> "dd",5=> "ee");//Associative ArraysPrint_r( each($arr)); Echo"<br/>";Print_r( each($arr)); Echo"<br/>";Print_r( each($arr)); Echo"<br/>";Print_r( each($arr)); Echo"<br/>";Print_r( each($arr)); Echo"<br/>";Print_r( each($arr));//list () special function//the only one "=" on the right side of the function, the right can only write an array//only for the index array//to map each element of the right array to the left variable$arra=Array(1,2,3,4,5,6);List($a,$b,$c,$d,$e,$f)=$arra;Echo $a; Echo"<br/>";//list ($a, $b, $d, $e, $f) = $arra, or//while loops, each (), list () iterates through the array while(List($key,$value)= each($arra)){ Echo"$key-$value<br/> "; }? ><?PHP//Each () and list () combination$contact=Array("ID" = 1, "name" = "Gao MoU", "Company" = "Company A", "address" = "Beijing");List($key,$value)= each($contact);Echo"$key=$value"; Echo"<br/>";List($key,$value)= each($contact);Echo"$key=$value";? ><br/><?PHP$contact=Array("ID" = 1, "name" = "Gao MoU", "Company" = "Company A", "address" = "Beijing"); while(List($key,$value)= each($contact)){ Echo"$key=$value. <br/> "; }?></body>
Each () in the php--Array, list (), and while loop iterate through the array