Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

PHP | SimpleXMLIterator hasChildren() Function

  • Last Updated : 29 Aug, 2019

The SimpleXMLIterator::hasChildren() function is an inbuilt function in PHP which is used to check whether the current SimpleXMLIterator element has sub-elements or not.


bool SimpleXMLIterator::hasChildren( void )

Parameters: This function does not accept any parameters.

Return Value: This function returns TRUE if the current element has sub-elements, FALSE otherwise.

Below program illustrates the SimpleXMLIterator::hasChildren() function in PHP:


// Store the xml element to variable
$xml = <<<XML
        <address>Noida India</address>
$xmlIt = new SimpleXMLIterator($xml);
// Loop starts from first element of xml and 
// run upto when elements are not valid
for( $xmlIt->rewind(); $xmlIt->valid(); $xmlIt->next() ) {
    if($xmlIt->hasChildren()) {
SimpleXMLIterator Object
    [email] =>
    [mobile] => +91-987654321


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!