PHP | AppendIterator getIteratorIndex() Function Last Updated : 20 Nov, 2019 Comments Improve Suggest changes Like Article Like Report The AppendIterator::getIteratorIndex() function is an inbuilt function in PHP which is used to get the index of the current inner iterator. Syntax: int AppendIterator::getIteratorIndex( void ) Parameters: This function does not accept any parameters. Return Value: This function returns an integer value which is the zero-based index of the current inner iterator. Below programs illustrate the AppendIterator::getIteratorIndex() function in PHP: Program 1: php <?php // Declare an ArrayIterator $arr1 = new ArrayIterator(array("Geeks", "for", "Geeks")); $arr2 = new ArrayIterator(array("Computer", "Science", "Portal")); // Create a new AppendIterator $itr = new AppendIterator; $itr->append($arr1); $itr->append($arr2); // Display the elements foreach ($itr as $key => $val) { echo "Iterator Index: " . $itr->getIteratorIndex() . " Key : " . $key . " Value: " . $val . "\n"; } ?> Output: Iterator Index: 0 Key : 0 Value: Geeks Iterator Index: 0 Key : 1 Value: for Iterator Index: 0 Key : 2 Value: Geeks Iterator Index: 1 Key : 0 Value: Computer Iterator Index: 1 Key : 1 Value: Science Iterator Index: 1 Key : 2 Value: Portal Program 2: php <?php // Declare an ArrayIterator $arr1 = new ArrayIterator( array( "a" => "Geeks", "b" => "for", "c" => "Geeks" ) ); $arr2 = new ArrayIterator( array( "x" => "Computer", "y" => "Science", "z" => "Portal" ) ); // Create a new AppendIterator $itr = new AppendIterator; $itr->append($arr1); $itr->append($arr2); // Display the elements foreach ($itr as $key => $val) { echo "Iterator Index: " . $itr->getIteratorIndex() . " Key : " . $key . " Value: " . $val . "\n"; } ?> Output: Iterator Index: 0 Key : a Value: Geeks Iterator Index: 0 Key : b Value: for Iterator Index: 0 Key : c Value: Geeks Iterator Index: 1 Key : x Value: Computer Iterator Index: 1 Key : y Value: Science Iterator Index: 1 Key : z Value: Portal Reference: https://www.php.net/manual/en/appenditerator.getiteratorindex.php Comment More infoAdvertise with us Next Article PHP | CachingIterator getInnerIterator() Function J jit_t Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads PHP | AppendIterator next() Function The AppendIterator::next() function is an inbuilt function in PHP which is used to move the element into the next element. Syntax: void AppendIterator::next( void ) Parameters: This function does not accept any parameters. Return Value: This function does not return any value. Below programs illustr 2 min read PHP | AppendIterator next() Function The AppendIterator::next() function is an inbuilt function in PHP which is used to move the element into the next element. Syntax: void AppendIterator::next( void ) Parameters: This function does not accept any parameters. Return Value: This function does not return any value. Below programs illustr 2 min read PHP | CachingIterator getInnerIterator() Function The CachingIterator::getInnerIterator() function is an inbuilt function in PHP which is used to return the iterator sent to the constructor. Syntax: Iterator CachingIterator::getInnerIterator( void ) Parameters: This function does not accept any parameters. Return Value: This function returns an obj 1 min read PHP | AppendIterator key() Function The AppendIterator::key() function is an inbuilt function in PHP which is used to return the current key. Syntax: scalar AppendIterator::key( void ) Parameters: This function does not accept any parameters. Return Value: This function returns the current key if it is valid or NULL otherwise. Below p 2 min read PHP | AppendIterator key() Function The AppendIterator::key() function is an inbuilt function in PHP which is used to return the current key. Syntax: scalar AppendIterator::key( void ) Parameters: This function does not accept any parameters. Return Value: This function returns the current key if it is valid or NULL otherwise. Below p 2 min read ArrayObject getIterator() Function in PHP 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. 1 min read Like