PHP 8.4.2 Released!

SimpleXMLElement::key

(PHP 8)

SimpleXMLElement::keyReturn current key

Beschreibung

public SimpleXMLElement::key(): string
Warnung

Prior to PHP 8.0, SimpleXMLElement::key() was only declared on the subclass SimpleXMLIterator.

This method gets the XML tag name of the current element.

Parameter-Liste

Diese Funktion besitzt keine Parameter.

Rückgabewerte

Returns the XML tag name of the element referenced by the current SimpleXMLElement object.

Fehler/Exceptions

Throws an Error on failure.

Changelog

Version Beschreibung
8.1.0 An Error is now thrown if SimpleXMLElement::key() is called on an invalid iterator. Previously, false was returned.

Beispiele

Beispiel #1 Get the current XML tag key

<?php
$xmlElement
= new SimpleXMLElement('<books><book>PHP basics</book><book>XML basics</book></books>');

echo
var_dump($xmlElement->key());
$xmlElement->rewind(); // rewind to the first element
echo var_dump($xmlElement->key());

?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

bool(false)
string(4) "book"

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top