PHP addChild() Function

The addChild() function adds a child element to the SimpleXML element.

public SimpleXMLElement SimpleXMLElement::addChild ( string $name [, string $value [, string $namespace ]] )

Adds a child element to the node and returns a SimpleXMLElement of the child.

Example -

ParameterDescription
nameThe name of the child element to add.
valueIf specified, the value of the child element.
namespaceIf specified, the namespace to which the child element belongs.

The addChild method returns a SimpleXMLElement object representing the child added to the XML node.