array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'en', ), 'this' => array ( 0 => 'arrayobject.getiterator.php', 1 => 'ArrayObject::getIterator', ), 'up' => array ( 0 => 'class.arrayobject.php', 1 => 'ArrayObject', ), 'prev' => array ( 0 => 'arrayobject.getflags.php', 1 => 'ArrayObject::getFlags', ), 'next' => array ( 0 => 'arrayobject.getiteratorclass.php', 1 => 'ArrayObject::getIteratorClass', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/spl/arrayobject/getiterator.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 5, PHP 7, PHP 8)
ArrayObject::getIterator — Create a new iterator from an ArrayObject instance
Create a new iterator from an ArrayObject instance.
This function has no parameters.
An iterator from an ArrayObject.
Example #1 ArrayObject::getIterator() example
<?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 above example will output:
1 => one 2 => two 3 => three