Funkcja getChildren() PHP
Przykład
Pobierz elementy potomne bieżącego elementu i wypisz nazwę i dane:
<?php
$bookxml = <<<XML
<bookstore>
<book>
<title>Everyday Italian</title>
<author>Giada De
Laurentiis</author>
</book>
<book>
<title>Harry Potter</title>
<author>J K.
Rowling</author>
</book>
<book>
<title>Learning XML</title>
<author>Erik T. Ray</author>
</book>
</bookstore>
XML;
$xml = new SimpleXMLIterator($bookxml);
for( $xml->rewind(); $xml->valid(); $xml->next() ) {
foreach($xml->getChildren()
as $name => $data) {
echo "The $name is '$data'";
echo "<br>";
}
}
?>
Definicja i użycie
Funkcja getChildren() zwraca elementy potomne bieżącego elementu.
Składnia
SimpleXMLIterator::getChildren()
Szczegóły techniczne
Wartość zwrotu: | Obiekt SimpleXMLIterator zawierający dzieci bieżącego elementu |
---|---|
Wersja PHP: | 5.0+ |
❮ Dokumentacja PHP SimpleXML