PHP SplObjectStorage rewind() Function Last Updated : 23 Jun, 2023 Comments Improve Suggest changes Like Article Like Report 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 <?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()); ?> Output: string(3) "GFG" string(5) "Geeks" string(3) "GFG" Program 2: php <?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(); } ?> Output: string(3) "GFG" string(12) "GeeksClasses" string(4) "SUDO" Reference: https://www.php.net/manual/en/splobjectstorage.rewind.php Comment More infoAdvertise with us Next Article PHP SplObjectStorage rewind() Function R R_Raj Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads PHP SplObjectStorage setInfo() Function The SplObjectStorage::setInfo() function is an inbuilt function in PHP which is used to set the data associated with the current iterator entry. Syntax: void SplObjectStorage::setInfo( $val ) Parameters: This function accepts a single parameter $val which specifies the data to be associate to the cu 1 min read PHP SplObjectStorage removeAll() Function The SplObjectStorage::removeAll() function is an inbuilt function in PHP which is used to remove all objects contained in another storage from the current storage. Syntax: void SplObjectStorage::removeAll( $obj ) Parameters: This function accepts a single parameter $obj which specify the storage to 1 min read PHP SplObjectStorage serialize() Function The SplObjectStorage::serialize() function is an inbuilt function in PHP which is used to serialize the result of the storage. Syntax: string SplObjectStorage::serialize() Parameters: This function does not accept any parameter. Return Value: This function returns a string which is the representatio 1 min read PHP SplObjectStorage key() Function The SplObjectStorage::key() function is an inbuilt function in PHP which is used to get the index of the currently pointing iterator. Syntax: int SplObjectStorage::key() Parameters: This function does not accept any parameter. Return Value: This function returns the index at which the iterator curre 1 min read PHP SplObjectStorage next() Function The SplObjectStorage::next() function is an inbuilt function in PHP which is used to move to next entry of storage. Syntax: void SplObjectStorage::next() Parameters: This function does not accept any parameter. Return Value: This function does not return any value. Below programs illustrate the SplO 1 min read Like