PHP 8.3.4 Released!

SimpleXMLElement::getChildren

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

SimpleXMLElement::getChildren現在の要素の子要素を返す

説明

public SimpleXMLElement::getChildren(): ?SimpleXMLElement
警告

PHP 8.0 より前のバージョンでは、 SimpleXMLElement::getChildren() は サブクラスの SimpleXMLIterator でのみ宣言されていました。

このメソッドは、現在の SimpleXMLElement 要素の子要素を含む SimpleXMLElement オブジェクトを返します。

パラメータ

この関数にはパラメータはありません。

戻り値

現在の要素の子要素を含む SimpleXMLElement オブジェクトを返します。

例1 現在の要素の子要素を返す

<?php
$xml
= <<<XML
<books>
<book>
<title>PHP Basics</title>
<author>Jim Smith</author>
</book>
<book>XML basics</book>
</books>
XML;

$xmlElement = new SimpleXMLElement($xml);
for (
$xmlElement->rewind(); $xmlElement->valid(); $xmlElement->next()) {
foreach(
$xmlElement->getChildren() as $name => $data) {
echo
"The $name is '$data' from the class " . get_class($data) . "\n";
}
}
?>

上の例の出力は以下となります。

The title is 'PHP Basics' from the class SimpleXMLElement
The author is 'Jim Smith' from the class SimpleXMLElement

add a note

User Contributed Notes

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