PHP hasChildren() Function
Example
Checks whether the current element has children, if it has; output the current element:
<?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>";
}
}
?>
Run Example »
Definition and Usage
The hasChildren() function checks whether the current element has children.
Syntax
SimpleXMLIterator::hasChildren()
Technical Details
Return Value: | TRUE if the current element has children. FALSE otherwise |
---|---|
PHP Version: | 5.0+ |
❮ PHP SimpleXML Reference