SimpleXMLIterator::getChildren

(PHP 5, PHP 7, PHP 8)

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

説明

public SimpleXMLIterator::getChildren(): SimpleXMLIterator

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

パラメータ

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

戻り値

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

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

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

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

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

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

関連キーワード:  要素, SimpleXMLIterator, getChildren, オブジェクト, パラメータ, from, hasChildren, public, メソッド, 関数