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
<?php
$str = new SplObjectStorage();
$obj = new StdClass;
$obj2 = new StdClass;
$str ->attach( $obj , "GFG");
$str ->attach( $obj2 , "Geeks");
$str -> rewind ();
var_dump( $str ->getInfo());
$str ->next();
var_dump( $str ->getInfo());
?>
|
Output:
string(3) "GFG"
string(5) "Geeks"
Program 2:
php
<?php
$str = new SplObjectStorage();
$obj1 = new StdClass;
$obj2 = new StdClass;
$obj3 = new StdClass;
$obj4 = new StdClass;
$str ->attach( $obj1 , "GeeksforGeeks");
$str ->attach( $obj2 , "GFG");
$str ->attach( $obj3 );
$str ->attach( $obj4 , "DSA");
$str -> rewind ();
while ( $str ->valid()) {
$index = $str ->key();
$object = $str ->current();
$data = $str ->getInfo();
var_dump( $index , $data );
$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
Last Updated :
11 May, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...