ArrayObject getIterator() Function in PHP Last Updated : 22 Mar, 2019 Comments Improve Suggest changes Like Article Like Report The getIterator() function of the ArrayObject class in PHP is used to create an iterator from an ArrayObject instance. This iterator can be used to iterate through the array of the respective ArrayObject. Syntax: ArrayIterator getIterator() Parameters: This function does not accepts any parameters. Return Value: This function returns an Iterator from an ArrayObject instance. Below programs illustrate the above function: Program 1: php <?php // PHP program to illustrate the // getIterator() function $arr = array("a" => "geeks", "b" => "are", "c" => "awesome"); // Create array object $arrObject = new ArrayObject($arr); // Create the iterator $itr = $arrObject->getIterator(); // Use iterator to traverse Array while($itr->valid()) { echo $itr->key().' => '.$itr->current()."\n"; $itr->next(); } ?> Output: a => geeks b => are c => awesome Program 2: php <?php // PHP program to illustrate the // getIterator() function $arr = array("a" => "Welcome", "b" => "2", "d" => "GFG"); // Create array object $arrObject = new ArrayObject($arr); // Create the iterator $itr = $arrObject->getIterator(); // Use iterator to traverse Array while($itr->valid()) { echo $itr->key().' => '.$itr->current()."\n"; $itr->next(); } ?> Output: a => Welcome b => 2 d => GFG Reference: http://php.net/manual/en/arrayobject.getiterator.php Comment More infoAdvertise with us Next Article ArrayObject getIterator() Function in PHP gopaldave Follow Improve Article Tags : Web Technologies PHP PHP-array PHP-function PHP-ArrayObject +1 More Similar Reads ArrayObject getIteratorClass() Function in PHP The getIteratorClass() function of the ArrayObject class in PHP is used to get the classname of the iterator used to iterate over this ArrayObject. Syntax: string getIteratorClass() Parameters: This function does not accepts any parameters. Return Value: This function returns the iterator classname 1 min read ArrayObject getArrayCopy() Function in PHP The getArrayCopy() function of the ArrayObject class in PHP is used to create a copy of this ArrayObject. This function returns the copy of the array present in this ArrayObject. Syntax: array getArrayCopy() Parameters: This function does not accepts any parameters. Return Value: This function retur 1 min read PHP | ArrayObject getFlags() Function The ArrayObject::getFlags() function is an inbuilt function in PHP which is used to get the behavior of flags of the ArrayObject. Syntax: int ArrayObject::getFlags( void ) Parameters: This function does not accept any parameters. Return Value: This function returns the behavior flags of the ArrayObj 2 min read PHP | ArrayObject setIteratorClass() Function The ArrayObject::setIteratorClass() function is an inbuilt function in PHP which is used to set the iterator classname for the ArrayObject. Syntax: void ArrayObject::setIteratorClass( string $iterator_class ) Parameters: This function accepts single parameter $iterator_class which holds the class na 2 min read PHP iterator_to_array() Function The iterator_to_array() function is an inbuilt function in PHP that is used to copy the iterator object (e.g. objects implementing the Iterator or IteratorAggregate interface) into an array. An iterator is an object that allows you to loop through a set of values one at a time without knowing the un 3 min read Like