In PHP, the each() function is used to return the key name and key value of the current element and move the internal pointer forward; this function can generate an element key name and key pointed to by the current internal pointer of the array An array composed of values. If the internal pointer exceeds the range of the array, the function returns false and the syntax is "each (array)".
The operating environment of this article: Windows 10 system, PHP version 5.6, Dell G3 computer
each() function returns the key name and key value of the current element and moves the internal pointer forward.
The key name and key value of the element will be returned in an array with four elements. Two elements (1 and Value) contain the key value, and two elements (0 and Key) contain the key name.
each(array)
array Required. Specifies the array to use.
Description
each() function generates an array consisting of the key name and key value of the element pointed to by the current internal pointer of the array, and moves the internal pointer forward.
The returned array includes four elements: key names 0, 1, key and value. Cells 0 and key contain the key names of the array cells, and 1 and value contain the data.
If the internal pointer exceeds the range of the array, this function will return FALSE.
The example is as follows:
<!DOCTYPE html> <html> <body> <?php $people = array("Bill", "Steve", "Mark", "David"); reset($people); while (list($key, $val) = each($people)) { echo "$key => $val<br>"; } ?> </body> </html>
Output result:
Tips: each() function is in PHP 7.2. Deprecated in 0.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What is the usage of each in php. For more information, please follow other related articles on the PHP Chinese website!