PHP key() Function
Example
Rewind to the first element and return the current key (which is the XML tag name of the current element):
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Do not forget me this weekend!</body>
</note>
XML;
$xml = new SimpleXMLIterator($note);
// rewind to the first element
$xml->rewind();
// return current key
var_dump($xml->key());
?>
Run Example »
Definition and Usage
The key() function returns the current key (which is the XML tag name of the current element).
Syntax
SimpleXMLIterator::key()
Technical Details
Return Value: | The XML tag name of the current element on success. FALSE otherwise |
---|---|
PHP Version: | 5.0+ |
❮ PHP SimpleXML Reference