Create a new iterator from an ArrayObject instance with ArrayObject::getIterator in PHP
Description
The following code shows how to create a new iterator from an ArrayObject instance with ArrayObject::getIterator.
Example
//example revised from php.net//w ww .j av a2s .co m
<?php
$array = array('1' => 'one',
'2' => 'two',
'3' => 'three');
$arrayobject = new ArrayObject($array);
$iterator = $arrayobject->getIterator();
while($iterator->valid()) {
echo $iterator->key() . ' => ' . $iterator->current() . "\n";
$iterator->next();
}
?>
The code above generates the following result.