downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

SimpleXMLIterator::key> <SimpleXMLIterator::getChildren
[edit] Last updated: Fri, 17 May 2013

view this page in

SimpleXMLIterator::hasChildren

(PHP 5 >= 5.1.0)

SimpleXMLIterator::hasChildrenIndique si l'entrée courante de SimpleXML est un objet

Description

bool SimpleXMLIterator::hasChildren ( void )

Cette méthode vérifie si l'objet courant SimpleXMLIterator 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;

$xmlIterator = new SimpleXMLIterator$xml );
for( 
$xmlIterator->rewind(); $xmlIterator->valid(); $xmlIterator->next() ) {
    if(
$xmlIterator->hasChildren()) {
        
var_dump($xmlIterator->current());
    }
}
?>

L'exemple ci-dessus va afficher :

object(SimpleXMLIterator)#2 (2) {
  ["title"]=>
  string(10) "PHP Basics"
  ["author"]=>
  string(9) "Jim Smith"
}



add a note add a note User Contributed Notes SimpleXMLIterator::hasChildren - [1 notes]
up
0
grummfy at gmail dot com
3 years ago
Hello,

just a note for people like me who encounter the problems :

<?php
foreach($xmlIterator as $x)
{
    if(
$x->hasChildren())
    {
       
//never reach
       
echo 'x : ';
       
var_dump($x->current());
    }
    if(
$xmlIterator->hasChildren())
    {
        echo
'iterator : ';
       
var_dump($x->current()); //all time null
       
var_dump($xmlIterator->current());
    }
}
?>

 
show source | credits | stats | sitemap | contact | advertising | mirror sites