src/Nodes/SVGNodeContainer.php
public function addChild(SVGNode $node, $index = null)
    {
        if ($node === $this || $node->parent === $this) {
            return $this;
        }

        if (isset($node->parent)) {
            $node->parent->removeChild($node);
        }

        $index = ($index !== null) ? $index : count($this->children);

        // insert and set new parent
        array_splice($this->children, $index, 0, array($node));
        $node->parent = $this;

        if ($node instanceof SVGStyle) {
            // if node is SVGStyle then add rules to container's style
            $this->addContainerStyle($node);
        }

        return $this;
    }
public function addChild(SVGNode $node, $index = null)
    {
        if ($node === $this || $node->parent === $this) {
            return $this;
        }

        if (isset($node->parent)) {
            $node->parent->removeChild($node);
        }

        $index = ($index !== null) ? $index : count($this->children);

        // insert and set new parent
        array_splice($this->children, $index, 0, array($node));
        $node->parent = $this;

        if ($node instanceof SVGStyle) {
            // if node is SVGStyle then add rules to container's style
            $this->addContainerStyle($node);
        }

        return $this;
    }
public function addChild ( SVGNode $ node , $ index = null ) { if ( $ node === $ this || $ node -> parent === $ this ) { return $ this ; } if ( isset ( $ node -> parent ) ) { $ node -> parent -> removeChild ( $ node ) ; } $ index = ( $ index !== null ) ? $ index : count ( $ this -> children ) ; // insert and set new parent array_splice ( $ this -> children , $ index , 0 , array ( $ node ) ) ; $ node -> parent = $ this ; if ( $ node instanceof SVGStyle ) { // if node is SVGStyle then add rules to container's style $ this -> addContainerStyle ( $ node ) ; } return $ this ; }
Inserts an SVGNode instance at the given index, or, if no index is given,
at the end of the child list.
Does nothing if the node already exists in this container.

@param SVGNode $node  The node to add to this container's children.
@param int     $index The position to insert at (optional).

@return $this This node instance, for call chaining.
Inserts an SVGNode instance at the given index or if no index is given at the end of the child list . Does nothing if the node already exists in this container .