PHP Conference Japan 2024

SimpleXMLElement::getChildren

(沒有版本資訊,可能只在 Git 中)

SimpleXMLElement::getChildren傳回目前元素的子元素

說明

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

在 PHP 8.0 之前,SimpleXMLElement::getChildren() 僅在子類別 SimpleXMLIterator 上宣告。

這個方法會傳回一個 SimpleXMLElement 物件,其中包含目前 SimpleXMLElement 元素的子元素。

參數

此函式沒有參數。

回傳值

傳回一個 SimpleXMLElement 物件,其中包含目前元素的子元素。

範例

範例 #1 傳回目前元素的子元素

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

$xmlElement = new SimpleXMLElement($xml);
for (
$xmlElement->rewind(); $xmlElement->valid(); $xmlElement->next()) {
foreach(
$xmlElement->getChildren() as $name => $data) {
echo
"$name 的值是 '$data',來自類別 " . get_class($data) . "\n";
}
}
?>

以上範例會輸出

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

新增註解

使用者貢獻的註解

此頁面沒有使用者貢獻的註解。
To Top