Open In App

PHP SplObjectStorage rewind() Function

Last Updated : 23 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
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
  
// 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
  
$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



Similar Reads

PHP | rewind( ) Function
The rewind() function in PHP is an inbuilt function which is used to set the position of the file pointer to the beginning of the file. Any data written to a file will always be appended if the file is opened in append ("a" or "a+") mode regardless of the file pointer position. The file on which the pointer has to be edited is sent as a parameter t
2 min read
PHP | SplFileObject rewind() Function
The SplFileObject::rewind() function is an inbuilt function of Standard PHP Library (SPL) in PHP which is used to Rewind the file to the first line. Syntax: void SplFileObject::rewind( $line_num) Parameters: This function does not accept any parameter. Return values: This function does not return any value. Below Programs illustrate the SplFileObje
1 min read
PHP SplDoublyLinkedList rewind() Function
The SplDoublyLinkedList::rewind() function is an inbuilt function in PHP which is used to rewind the iterator back to the start or beginning. Syntax: void SplDoublyLinkedList::rewind( void ) Parameters: This function does not accepts any parameters. Return Value: It does not return any value. Below programs illustrate the SplDoublyLinkedList::rewin
1 min read
PHP SplFixedArray rewind() Function
The SplFixedArray::rewind() function is an inbuilt function in PHP which is used to rewind the array iterator to start position. Syntax: void SplFixedArray::rewind() Parameters: This function does not accept any parameter. Return Value: This function does not return any value. Below programs illustrate the SplFixedArray::rewind() function in PHP: P
1 min read
PHP | SimpleXMLIterator rewind() Function
The SimpleXMLIterator::rewind() function is an inbuilt function in PHP which is used to rewind the SimpleXMLIterator to the first element. Syntax: void SimpleXMLIterator::rewind( void ) Parameters: This function does not accept any parameters. Return Value: This function does not return any value. Below programs illustrate the SimpleXMLIterator::re
1 min read
PHP | AppendIterator rewind() Function
The AppendIterator::rewind() function is an inbuilt function in PHP which is used to rewind to the first element of the first inner Iterator. Syntax: void AppendIterator::rewind( void ) Parameters: This function does not accept any parameters. Return Value: This function does not return any value. Below programs illustrate the AppendIterator::rewin
1 min read
PHP | ArrayIterator rewind() Function
The ArrayIterator::rewind() function is an inbuilt function in PHP which is used to rewind the array back to the start. Syntax: void ArrayIterator::rewind( void ) Parameters: This function does not accept any parameters. Return Value: This function does not return any value. Below programs illustrate the ArrayIterator::rewind() function in PHP: Pro
1 min read
PHP | CachingIterator rewind() Function
The CachingIterator::rewind() function is an inbuilt function in PHP which is used to rewind the iterator. Syntax: void CachingIterator::rewind( void ) Parameters: This function does not accept any parameters. Return Value: This function does not return any value. Below programs illustrate the CachingIterator::rewind() function in PHP: Program 1:
1 min read
PHP | FilesystemIterator rewind() Function
The FilesystemIterator::rewind() function is an inbuilt function in PHP which is used to rewinds back to the beginning of the file. Syntax: void FilesystemIterator::rewind( void ) Parameters: This function does not accept any parameters. Return Value: This function does not return any value. Below programs illustrate the FilesystemIterator::rewind(
2 min read
PHP | DirectoryIterator rewind() Function
The DirectoryIterator::rewind() function is an inbuilt function in PHP which is used to rewind the DirectoryIterator back to the start position. Syntax: void DirectoryIterator::rewind( void ) Parameters: This function does not accept any parameters. Return Value: This function does not return any value. Below programs illustrate the DirectoryIterat
2 min read