The each function returns the current key/value pair in the array and moves the array pointer one step forward
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. If you want to iterate through the array again with each, you must use Reset ().
Parameter introduction:
Parameters |
Description |
Array |
Necessary. Specify the array to use. |
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.
return value:
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. Each () returns FALSE if the internal pointer crosses the end of the array.
Each function instance one:
<?php
$foo = Array (
"Bob",
"Fred",
"Jussi",
"Jouni",
"Egon",
"Marliese"
) ;
$bar = each ($foo);
Print_r ($bar);
? >
Operation results;
Array
(
[1] => Bob
[Value] => bob
[0] => 0
[Key] => 0
)
instance of each function two:
Each () walks the array with the list ()
<?php
$fruit = Array (
' a ' => ' apple ',
' B ' => ' banana ',
' C ' => ' cranberry '
);
Reset ($fruit);
while (the list ($key, $val) = each ($fruit)) {
echo "$key => $val <br/>"
;
>
Run Result:
A => apple
b => Banana
C => Cranberry
Thank you for reading, I hope to help you, thank you for your support for this site!