As well as the page @dalecosp links, which says
Return Values
Returns the current key and value pair from the array array. This pair is returned in a four-element array, with the keys 0
, 1
, key
, and value
. Elements 0
and key
contain the key name of the array element, and 1
and value
contain the data.
you'll also want to look at the page for the loop's replacement, foreach, which says
foreach (iterable_expression as $key => $value)
statement
... will additionally assign the current element's key to the $key variable on each iteration.
What I'm getting at is, it's worth reading the manual.
Edit: I went digging through old versions of the manual, back to PHP 4, and found where the foreach page still said this:
The following are also functionally identical:
<?php
$arr = array("one", "two", "three");
reset($arr);
while (list($key, $value) = each($arr)) {
echo "Key: $key; Value: $value<br />\n";
}
foreach ($arr as $key => $value) {
echo "Key: $key; Value: $value<br />\n";
}
?>
Why any PHP book written in the last twenty years would still use while(...each...)
is probably down to lazy editing of even earlier versions.