- reset: documentation ( source)
<?php
$x = array(0 => 1, 2 => 3, 4 => 5, 6 => 7, 8 => 9);
each($x);
$it = new ArrayIterator($x);
while ($it->valid()) {
$key = $it->key();
$value = $it->current();
$it->next();
echo "first loop (each):" . $key . "=>" . $value . "\n";
if ($key == 4) {
break;
}
}
while ($it->valid()) {
$key = $it->key();
$value = $it->current();
$it->next();
echo "second loop (each):" . $key . "=>" . $value . "\n";
}
reset($x);
while (list($key, $value) = each($x)) {
echo "first loop (each):" . $key . "=>" . $value . "\n";
if ($key == 4) {
break;
}
}
while (list($key, $value) = each($x)) {
echo "second loop (each):" . $key . "=>" . $value . "\n";
}