PHP hasChildren() Fonction

❮ Référence PHP SimpleXML

Exemple

Vérifie si l'élément actuel a des enfants ; si c'est le cas, affiche l'élément actuel :

<?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() ) {
if($xml->hasChildren()) {
var_dump($xml->current());
echo "<br>";
}
}
?>
Exécuter l'exemple »

Définition et Utilisation

La fonction hasChildren() vérifie si l'élément actuel a des enfants.


Syntaxe

SimpleXMLIterator::hasChildren()

Détails Techniques

Valeur de retour : TRUE si l'élément actuel a des enfants, FALSE sinon.
Version PHP : 5.0+

❮ Référence PHP SimpleXML