PHP Tutorial - PHP children() Function






The children() function finds the children of a specified node.

Syntax

PHP children() Function has the following syntax.

children(ns,is_prefix);

Parameter

ParameterIs requiredDescription
nsOptional.An XML namespace
is_prefixOptional.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.  j  a  v a2s  . com
$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.