SimpleXMLIterator::getChildren()函數是PHP中的內置函數,用於返回包含當前元素子元素的SimpleXMLIterator對象。
用法:
SimpleXMLIterator SimpleXMLIterator::getChildren( void )
參數:該函數不接受任何參數。
返回值:該函數返回SimpleXMLIterator對象,該對象包含當前元素的子元素。
以下示例程序旨在說明PHP中的SimpleXMLIterator::getChildren()函數:
程序:
<?php
// Store the xml element to variable
$xml = <<<XML
<organization>
<name>GeeksforGeeks</name>
<address>Noida India</address>
<contact>
<email>abc@geeksforgeeks.org</email>
<mobile>+91-987654321</mobile>
</contact>
</organization>
XML;
$xmlIt = new SimpleXMLIterator($xml);
// Loop starts from first element of xml and
// run upto when elements are not valid
for( $xmlIt->rewind(); $xmlIt->valid(); $xmlIt->next() ) {
foreach($xmlIt->getChildren() as $element => $content) {
echo "The content of '$element' element is '$content'" . "\n";
}
}
?>
輸出:
The content of 'email' element is 'abc@geeksforgeeks.org' The content of 'mobile' element is '+91-987654321'
參考: https://www.php.net/manual/en/simplexmliterator.getchildren.php
相關用法
- PHP SimpleXMLIterator next()用法及代碼示例
- PHP SimpleXMLIterator key()用法及代碼示例
- PHP SimpleXMLIterator current()用法及代碼示例
- PHP SimpleXMLIterator rewind()用法及代碼示例
- PHP SimpleXMLIterator hasChildren()用法及代碼示例
- PHP SimpleXMLIterator valid()用法及代碼示例
- PHP abs()用法及代碼示例
- p5.js pan()用法及代碼示例
- PHP each()用法及代碼示例
- p5.js box()用法及代碼示例
- d3.js d3.map.has()用法及代碼示例
- PHP pow( )用法及代碼示例
注:本文由純淨天空篩選整理自jit_t大神的英文原創作品 PHP | SimpleXMLIterator getChildren() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。