PHP getChildren() Fonction

❮ Référence PHP SimpleXML

Exemple

Obtenez les éléments enfants de l'élément courant et affichez leur nom et leurs données :

<?php
$bookxml = <<<XML
<bookstore>
<book>
<title>Everyday Italian</title>
<author>Giada De Laurentiis</author>
</book>
<book>
<title>Harry Potter</title>
<author>J K. Rowling</author>
</book>
<book>
<title>Learning XML</title>
<author>Erik T. Ray</author>
</book>
</bookstore>
XML;

$xml = new SimpleXMLIterator($bookxml);

for( $xml->rewind(); $xml->valid(); $xml->next() ) {
foreach($xml->getChildren() as $name => $data) {
echo "Le $name est '$data'";
echo "<br>";
}
}
?>
Exécuter l'exemple »

Définition et Utilisation

La fonction getChildren() retourne les éléments enfants de l'élément courant.


Syntaxe

SimpleXMLIterator::getChildren()

Détails Techniques

Valeur de retour : Un objet SimpleXMLIterator contenant les enfants de l'élément courant
Version PHP : 5.0+

❮ Référence PHP SimpleXML