Syntaxe :void SimpleXMLIterator ::rewind (void)
Paramètres :cette fonction ne prend aucun paramètre.
Retour value :cette fonction ne renvoie aucune valeur.Les programmes suivants illustrent la fonction SimpleXMLIterator::rewind() en PHP :
Programme 1 :
// Enregistre l`élément xml dans une variable
$xml
= < < < XML
< organisation >
< nom > GeeksforGeeks
Noida India
< contact >
< email > [email protected]< / email >
+ 91-987654321 < / portable >
< / contact >
< / organisation >
XML ;
$xmlIt
=
nouveau
SimpleXMLIterator (
$xml
);
/ / Utilisez la fonction rewind() pour rembobiner
// jusqu`au premier élément
$xmlIt
->
rembobiner
();
// Utilisez la fonction next() pour naviguer vers
/ / élément suivant
$xm lIt
-> next();
$xmlIt
-> next();
// Afficher le résultat
var_dump (
$xmlIt
-> current());
?>
Quitter :object (SimpleXMLIterator ) # 2 (2) {["email"] => string (21) " [email protected]" ["mobile"] => string (13) "+ 91-987654321"}
Programme 2 : < ? php
// Enregistre l`élément xml dans une variable
$xml
= < < < XML
< organisation >
< nom > GeeksforGeeks
Noida India
< contact >
< email > [email protected]< / email >
+ 91-987654321 < / portable >
< / contact >
< / organisation >
XML ;
$xmlIt
=
nouveau
SimpleXMLIterator (
$xml
);
/ / la boucle démarre à partir du premier élément xml et
// s`exécute lorsque les éléments sont invalides
pour
(
$xmlIt
->
rewind
();
$xmlIt
-> valid() ;
$xmlIt
-> suivant()) {/code>
var_dump (
$xmlIt
-> key());
}
?>
Quitter :< /b>chaîne (4 ) "nom" chaîne (7) "adresse" chaîne (7) "contact"
Lien : https://www.php .net/manual/en/simplexmliterator.rewind.php