PHP children() Function
Description
The children() function finds the children of a specified node.
Syntax
PHP children() Function has the following syntax.
children(ns,is_prefix);
Parameter
Parameter | Is required | Description |
---|---|---|
ns | Optional. | An XML namespace |
is_prefix | Optional. | If TRUE, ns is regarded as a prefix. If FALSE, ns is regarded as a namespace URL |
Return
Returns a SimpleXMLElement object
Example
Find the children of the note node:
<?php/*from w ww.java2 s. c o m*/
$note=<<<XML
<book>
<name>PHP</name>
<name>Java</name>
</book>
XML;
$xml=simplexml_load_string($note);
foreach ($xml->children() as $child){
echo "Child node: " . $child . "\n";
}
?>
The code above generates the following result.