PHP SimpleXMLIterator key () function

PHP

Syntax:
mixed SimpleXMLIterator::key (void)
Parameters:this function takes no parameters.Return Value:this function returns the XML tag name of the object`s SimpleXMLIterator element on success, or FALSE on error.Below the program illustrates the SimpleXMLIterator::key() function in PHP:Program :  
// Save the xml element to a variable $xml = < < < XML < organization > < name > GeeksforGeeks < / name > < address > Noida India < / address > < contact > < email > [email protected]< / email > < mobile > + 91-987654321 < / mobile > < / contact > < / organization > XML; $xmlIt = new SimpleXMLIterator ( $xml );  
// the loop starts from the first xml element and
// run when elements are invalid for ( $xmlIt -> rewind (); $xmlIt -> valid(); $xmlIt -> next()) {   var_dump ( $xmlIt -> key()); }  
?>
Exit:
string (4 ) "name" string (7) "address" string (7) "contact"
Link: https://www.php.net/manual/en/simplexmliterator.key.php



Get Solution for free from DataCamp guru