PHP AppendIterator rewind () Function

PHP

Syntax:
void AppendIterator::rewind (void)
Parameters:This function takes no parameters.Return value:This function does not return any value.The following programs illustrate the AppendIterator function::rewind() in PHP:Program 1:  
// Declare ArrayIterator $arr1 = new ArrayIterator ( array ( "Geeks" , "for" , "Geeks" ));  
// Create a new AppendIterator $itr = new AppendIterator; $itr -> append ( $arr1 );  
// Using the rewind function $itr -> rewind ();  
// Get current data var_dump ( $itr -> current());  
// Go to next object $itr -> next();  
// Get current data var_dump ( $itr -> current());  
// Using the rewind function again $itr -> rewind ();  
// Get current data var_dump ( $itr -> current());  
?>
Exit:
string (5 ) "Geeks" string (3) "for" string (5) "Geeks"
Program 2:  
// Declare 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 );  
// Using the rewind function $itr -> rewind (); while ( $itr -> valid()) { var_dump ( $itr -> current()); // Move to next element $itr -> next(); }  
?>
Exit:
string (5 ) "Geeks" string (3) "for" string (5) "Geeks" string (8) "Computer" string (7) "Science" string (6) "Portal"
Link : https://www.php.net/manual/en/appenditerator.rewind.php



Get Solution for free from DataCamp guru