PHP SplObjectStorage next() Function Last Updated : 11 May, 2023 Comments Improve Suggest changes Like Article Like Report 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 SplObjectStorage::next() function in PHP: Program 1: php <?php // Create an empty SplObjectStorage $str = new SplObjectStorage(); $obj = new StdClass; $obj2 = new StdClass; // Use attach() function to add object $str->attach($obj, "GFG"); $str->attach($obj2, "Geeks"); $str->rewind(); // Get the current data var_dump($str->getInfo()); // Move on to next object $str->next(); // Print result of next entry var_dump($str->getInfo()); ?> Output:string(3) "GFG" string(5) "Geeks" Program 2: php <?php // Create an Empty SplObjectStorage $str = new SplObjectStorage(); $obj1 = new StdClass; $obj2 = new StdClass; $obj3 = new StdClass; $obj4 = new StdClass; // Use attach() function to add object $str->attach($obj1, "GeeksforGeeks"); $str->attach($obj2, "GFG"); $str->attach($obj3); $str->attach($obj4, "DSA"); $str->rewind(); // Iterate and print data on each index while($str->valid()) { // Get index $index = $str->key(); $object = $str->current(); $data = $str->getInfo(); var_dump($index, $data); // Moving each time next entry $str->next(); } ?> Output:int(0) string(12) "GeksforGeeks" int(1) string(3) "GFG" int(2) NULL int(3) string(3) "DSA" Reference: https://www.php.net/manual/en/splobjectstorage.next.php Create Quiz Comment R R_Raj Follow 0 Improve R R_Raj Follow 0 Improve Article Tags : Web Technologies PHP PHP-function Explore BasicsPHP Syntax4 min readPHP Variables5 min readPHP | Functions6 min readPHP Loops4 min readArrayPHP Arrays5 min readPHP Associative Arrays4 min readMultidimensional arrays in PHP5 min readSorting Arrays in PHP4 min readOOPs & InterfacesPHP Classes2 min readPHP | Constructors and Destructors5 min readPHP Access Modifiers4 min readMultiple Inheritance in PHP4 min readMySQL DatabasePHP | MySQL Database Introduction4 min readPHP Database connection2 min readPHP | MySQL ( Creating Database )3 min readPHP | MySQL ( Creating Table )3 min readPHP AdvancePHP Superglobals6 min readPHP | Regular Expressions12 min readPHP Form Handling4 min readPHP File Handling4 min readPHP | Uploading File3 min readPHP Cookies9 min readPHP | Sessions7 min read Like