(PHP 8)
SimpleXMLElement::hasChildren — Vérifie si l'élément actuel a des sous-éléments
Antérieur à PHP 8.0, SimpleXMLElement::hasChildren() n'était déclarée que sur la sous-classe SimpleXMLIterator.
Cette méthode vérifie si l'objet courant SimpleXMLElement a des sous-éléments.
Cette fonction ne contient aucun paramètre.
Exemple #1 Vérifie si un élément a des sous-éléments
<?php
$xml = <<<XML
<books>
    <book>
        <title>PHP Basics</title>
        <author>Jim Smith</author>
    </book>
    <book>XML basics</book>
</books>
XML;
$xmlElement = new SimpleXMLElement($xml);
for ($xmlElement->rewind(); $xmlElement->valid(); $xmlElement->next()) {
    if ($xmlElement->hasChildren()) {
        var_dump($xmlElement->current());
    }
}
?>L'exemple ci-dessus va afficher :
object(SimpleXMLElement)#2 (2) {
  ["title"]=>
  string(10) "PHP Basics"
  ["author"]=>
  string(9) "Jim Smith"
}
