hasChildren ()

This method checks whether the current SimpleXMLIterator element has sub-elements.

Access

public

Returns

Type

Description

boolean

TRUE if the current element has sub-elements, otherwise FALSE

Examples

Check whether the current element has sub-elements

$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());
    }
}
Result:
object(SimpleXMLIterator)#2 (2) {
  ["title"]=>
  string(10) "PHP Basics"
  ["author"]=>
  string(9) "Jim Smith"
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback