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  Â// Declare an ArrayIterator $arr1= newArrayIterator(array("Geeks", "for", "Geeks")); $arr2= newArrayIterator(array("Computer", "Science", "Portal"));  Â// Create a new AppendIterator $itr= newAppendIterator; $itr->append($arr1); $itr->append($arr2);  Â// Display the elements foreach($itras$key=> $val) {     echo"Iterator Index: ". $itr->getIteratorIndex()         . "  Key : ". $key. "  Value: ". $val. "\n";  }  Â?>  | 
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  Â// Declare an ArrayIterator $arr1= newArrayIterator(     array(         "a"=> "Geeks",         "b"=> "for",         "c"=> "Geeks"    ) );  Â$arr2= newArrayIterator(     array(         "x"=> "Computer",         "y"=> "Science",         "z"=> "Portal"    ) );  Â// Create a new AppendIterator $itr= newAppendIterator; $itr->append($arr1); $itr->append($arr2);  Â// Display the elements foreach($itras$key=> $val) {     echo"Iterator Index: ". $itr->getIteratorIndex()         . "  Key : ". $key. "  Value: ". $val. "\n";  }  Â?>  | 
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


 
                                    







