Each function returns the current key/value pair in the array and moves the array pointer forward one step
Basic syntax
Array each (array & $array)
After each (), the array pointer stays in the next cell in the array, or when the end of the array is encountered, the last cell. If you want to iterate through the array again, you must use Reset ().
Parameter description:
The each () function generates an array of the key names and key values of the elements pointed to by the current internal pointer to the array, and moves the internal pointer forward.
return value:
Returns the key/value pair of the current pointer position in an array and moves the array pointer forward. A key-value pair is returned as an array of four cells with the key name 0,1,key and value. Unit 0 and key contain the key name of the array cell, and 1 and value contain the data. If the internal pointer crosses the end of the array, each () returns FALSE.
Each function instance one:
<?php$foo = Array ( "Bob", " Fred", " Jussi", "Jouni", "Egon", "Marliese"); $bar = each ($ Foo);p Rint_r ($bar);? >
Operation result;
Array
(
[1] = Bob
[Value] = Bob
[0] = 0
[Key] = 0
)
Each function instance two:
Each () iterates through the array with the list ()
<?php$fruit = Array ( ' a ' = = ' Apple ', ' b ' = ' banana ', ' c ' = ' cranberry '); reset ($fruit); while ( List ($key, $val) = each ($fruit)) { echo "$key + = $val <br/>";}? >
Operation Result:
A = Apple
b = Banana
c = Cranberry
Thank you for reading, hope to help everyone, thank you for the support of this site!