- reset: documentation ( source)
- key: documentation ( source)
- next: documentation ( source)
- current: documentation ( source)
<?php
$fruit = array('a' => 'apple', 'b' => 'banana', 'c' => 'cranberry');
reset($fruit);
while (list($key, $val) = each($fruit)) {
echo "$key => $val\n";
}
foreach ($fruit as $key => $val) {
echo "$key => $val\n";
}
function my_each($array)
{
$key = key($array);
if (!isset($key)) {
return false;
}
$current = current($array);
next($array);
return [$key, $current];
}
reset($fruit);
while (list($key, $val) = each($fruit)) {
echo "$key => $val\n";
}