This article describes how to obtain the keys and values of the current array in the php array. For more information, see. In the php array function, the each () function returns the current key/value pair of input_array and pushes the pointer to a position. Format: array each (array) The returned array contains four keys. Keys 0 and key contain the key name, while Keys 1 and value contain the corresponding data. If the pointer before execution of each () is located at the end of the array, false is returned. For example:
apple [value] => apple [0] => 0 [key] => 0 ) ?> Each () is often used in combination with list () to traverse arrays. For example, the entire array is output cyclically:
$val "; } //by bbs.it-home.org // 0 => apple // 1 => banana // 2 => orange // 3 => pear ?> Since the original array pointer is reset when an array is assigned to another array, if $ fruits is assigned to another variable in the previous example, an infinite loop will occur. This completes the array traversal. |