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. :)
ArrayIterator::next
(PHP 5 >= 5.0.0)
ArrayIterator::next — Se déplace vers la prochaine entrée
Description
public void ArrayIterator::next
( void
)
Se déplace vers la prochaine entrée.
Liste de paramètres
Cette fonction ne contient aucun paramètre.
Valeurs de retour
Aucune valeur n'est retournée.
Exemples
Exemple #1 Exemple avec ArrayIterator::next()
<?php
$arrayobject = new ArrayObject();
$arrayobject[] = 'zero';
$arrayobject[] = 'one';
$iterator = $arrayobject->getIterator();
while($iterator->valid()) {
echo $iterator->key() . ' => ' . $iterator->current() . "\n";
$iterator->next();
}
?>
L'exemple ci-dessus va afficher :
0 => zero 1 => one
onelsonsenna at gmail dot com
06-Oct-2011 01:09
