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 SplObjectStorage::next() function in PHP:
Program 1:
<?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()); ?> |
string(3) "GFG" string(5) "Geeks"
Program 2:
<?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, "GeksforGeeks"); $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(); } ?> |
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
Recommended Posts:
- PHP | SplObjectStorage contains() Function
- PHP | SplObjectStorage key() Function
- PHP | SplObjectStorage count() Function
- PHP | SplObjectStorage offsetSet() Function
- PHP | SplObjectStorage offsetUnset() Function
- PHP | SplObjectStorage removeAll() Function
- PHP | SplObjectStorage getinfo() Function
- PHP | SplObjectStorage removeAllExcept() Function
- PHP | SplObjectStorage current() Function
- PHP | SplObjectStorage attach() Function
- PHP | SplObjectStorage offsetExists() Function
- PHP | SplObjectStorage offsetGet() Function
- PHP | SplObjectStorage detach() Function
- PHP | SplObjectStorage addAll() Function
- PHP | SplObjectStorage unserialize() 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.



