CakeFest 2024: The Official CakePHP Conference

SimpleXMLElement::hasChildren

(No version information available, might only be in Git)

SimpleXMLElement::hasChildrenVérifie si l'élément actuel a des sous-éléments

Description

public SimpleXMLElement::hasChildren(): bool
Avertissement

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.

Liste de paramètres

Cette fonction ne contient aucun paramètre.

Valeurs de retour

true si l'entrée courante a des sous-éléments, false sinon.

Exemples

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"
}

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top