Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

PHP | SimpleXMLIterator key() Function

  • Last Updated : 29 Aug, 2019

The SimpleXMLIterator::key() function is an inbuilt function in PHP which is used to return the key of current element.


mixed SimpleXMLIterator::key( void )

Parameters: This function does not accept any parameters.

Return Value: This function returns the XML tag name of the element SimpleXMLIterator object on success or FALSE on failure.

Below program illustrates the SimpleXMLIterator::key() 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() ) {
string(4) "name"
string(7) "address"
string(7) "contact"


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!