PHP 8.6.0 Beta 1 is available for testing

ArrayIterator::next

(PHP 5, PHP 7, PHP 8)

ArrayIterator::nextDesplaza a la siguiente entrada

Descripción

public function ArrayIterator::next(): void

Mueve el iterador a la siguiente entrada.

Parámetros

Esta función no contiene ningún parámetro.

Valores devueltos

No se retorna ningún valor.

Ejemplos

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

Found A Problem?

Learn How To Improve This PageSubmit a Pull RequestReport a Bug
+add a note

User Contributed Notes 1 note

up
1
onelsonsenna at gmail dot com
14 years ago
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. :)
+add a note

AltStyle によって変換されたページ (->オリジナル) /