Dutch PHP Conference 2025 - Call For Papers

SimpleXMLElement::key

(No version information available, might only be in Git)

SimpleXMLElement::keyReturn current key

Опис

public SimpleXMLElement::key(): string
Увага

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.

Параметри

У цієї функції немає параметрів.

Значення, що повертаються

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

Помилки/виключення

Throws an Error on failure.

Журнал змін

Версія Опис
8.1.0 An Error is now thrown if SimpleXMLElement::key() is called on an invalid iterator. Previously, false was returned.

Приклади

Приклад #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());

?>

Поданий вище приклад виведе:

bool(false)
string(4) "book"

add a note

User Contributed Notes

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