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::rewind() function in PHP:
Program 1:
<?php
$xml = <<<XML
<organization>
<name>GeeksforGeeks</name>
<address>Noida India</address>
<contact>
<email>abc@geeksforgeeks.org</email>
<mobile>+91-987654321</mobile>
</contact>
</organization>
XML;
$xmlIt = new SimpleXMLIterator( $xml );
$xmlIt -> rewind ();
$xmlIt ->next();
$xmlIt ->next();
var_dump( $xmlIt ->current());
?>
|
Output:
object(SimpleXMLIterator)#2 (2) {
["email"]=>
string(21) "abc@geeksforgeeks.org"
["mobile"]=>
string(13) "+91-987654321"
}
Program 2:
<?php
$xml = <<<XML
<organization>
<name>GeeksforGeeks</name>
<address>Noida India</address>
<contact>
<email>abc@geeksforgeeks.org</email>
<mobile>+91-987654321</mobile>
</contact>
</organization>
XML;
$xmlIt = new SimpleXMLIterator( $xml );
for ( $xmlIt -> rewind (); $xmlIt ->valid(); $xmlIt ->next() ) {
var_dump( $xmlIt ->key());
}
?>
|
Output:
string(4) "name"
string(7) "address"
string(7) "contact"
Reference: https://www.php.net/manual/en/simplexmliterator.rewind.php
Last Updated :
20 Jul, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...