(PHP 5, PHP 7, PHP 8)
ArrayIterator::next — Desplaza a la siguiente entrada
Esta función no contiene ningún parámetro.
No se retorna ningún valor.
Ejemplo #1 Ejemplo de ArrayIterator::next()
<?php
$arrayobject = new ArrayObject();
$arrayobject[] = 'cero';
$arrayobject[] = 'uno';
$iterator = $arrayobject->getIterator();
while($iterator->valid()) {
echo $iterator->key() . ' => ' . $iterator->current() . "\n";
$iterator->next();
}
?>El ejemplo anterior mostrará:
0 => cero 1 => uno
If you use exchangeArray method of ArrayObject and then next method of ArrayIterator like this:
<?php
$fruits = array("apple", "grape", "lemon");
$colors = array("blue", "yellow", "green");
$arrayObject = new ArrayObject($fruits);
$arrayIterator = $arrayObject->getIterator();
while($arrayIterator->valid()) {
if ($arrayIterator->current() == "grape") {
$arrayObject->exchangeArray($colors);
}
$arrayIterator->next();
}
?>
You will receive:
PHP Notice: ArrayIterator::next(): Array was modified outside object and internal position is no longer valid
So be careful with next and prev operations. :)