PHP | SplObjectStorage rewind() Function
The SplObjectStorage::rewind() function is an inbuilt function in PHP which is used to rewind the iterator to the first storage element.
Syntax:
void SplObjectStorage::rewind()
Parameters: This function does not accept any parameter.
Return Value: This function does not return any value.
Below programs illustrate the SplObjectStorage::rewind() function in PHP:
Program 1:
<?php // Create an empty SplObjectStorage $str = new SplObjectStorage(); $obj = new StdClass; $obj2 = new StdClass; $obj3 = new StdClass; $str->attach($obj, "GFG"); $str->attach($obj2, "Geeks"); $str->attach($obj3, "FORK JAVA"); // Using rewind function $str->rewind(); // Get current data var_dump($str->getInfo()); // Move on to next object $str->next(); // Get current data var_dump($str->getInfo()); // Again using rewind function $str->rewind(); // Get current data var_dump($str->getInfo()); ?> |
string(3) "GFG" string(5) "Geeks" string(3) "GFG"
Program 2:
<?php $obj1 = new StdClass; $obj2 = new StdClass; $obj3 = new StdClass; $gfg = new SplObjectStorage(); $gfg[$obj1] = "GFG"; $gfg[$obj2] = "GeeksClasses"; $gfg[$obj3] = "SUDO"; // Using rewind function $gfg->rewind(); while($gfg->valid()) { var_dump($gfg->getInfo()); // Moving to next element $gfg->next(); } ?> |
string(3) "GFG" string(12) "GeeksClasses" string(4) "SUDO"
Reference: https://www.php.net/manual/en/splobjectstorage.rewind.php
Recommended Posts:
- PHP | rewind( ) Function
- PHP | SplDoublyLinkedList rewind() Function
- PHP | SplFileObject rewind() Function
- PHP | SimpleXMLIterator rewind() Function
- PHP | SplFixedArray rewind() Function
- PHP | SplObjectStorage contains() Function
- PHP | SplObjectStorage next() Function
- PHP | SplObjectStorage key() Function
- PHP | SplObjectStorage attach() Function
- PHP | SplObjectStorage count() Function
- PHP | SplObjectStorage addAll() Function
- PHP | SplObjectStorage valid() Function
- PHP | SplObjectStorage current() Function
- PHP | SplObjectStorage offsetExists() Function
- PHP | SplObjectStorage detach() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



