public function appendChild($nodes)
    {
        $returnArray = true;

        if (!is_array($nodes)) {
            $nodes = [$nodes];

            $returnArray = false;
        }

        $result = [];

        foreach ($nodes as $node) {
            if ($node instanceof Element) {
                $node = $node->getNode();
            }

            if (!$node instanceof DOMNode) {
                throw new InvalidArgumentException(sprintf('Argument 1 passed to %s must be an instance of %s\Element or DOMNode, %s given', __METHOD__, __NAMESPACE__, (is_object($node) ? get_class($node) : gettype($node))));
            }

            Errors::disable();

            $cloned = $node->cloneNode(true);
            $newNode = $this->document->importNode($cloned, true);

            $result[] = $this->document->appendChild($newNode);

            Errors::restore();
        }

        $result = array_map(function (DOMNode $node) {
            return new Element($node);
        }, $result);

        return $returnArray ? $result : $result[0];
    }
public function appendChild($nodes)
    {
        $returnArray = true;

        if (!is_array($nodes)) {
            $nodes = [$nodes];

            $returnArray = false;
        }

        $result = [];

        foreach ($nodes as $node) {
            if ($node instanceof Element) {
                $node = $node->getNode();
            }

            if (!$node instanceof DOMNode) {
                throw new InvalidArgumentException(sprintf('Argument 1 passed to %s must be an instance of %s\Element or DOMNode, %s given', __METHOD__, __NAMESPACE__, (is_object($node) ? get_class($node) : gettype($node))));
            }

            Errors::disable();

            $cloned = $node->cloneNode(true);
            $newNode = $this->document->importNode($cloned, true);

            $result[] = $this->document->appendChild($newNode);

            Errors::restore();
        }

        $result = array_map(function (DOMNode $node) {
            return new Element($node);
        }, $result);

        return $returnArray ? $result : $result[0];
    }
public function appendChild ( $ nodes ) { $ returnArray = true ; if ( ! is_array ( $ nodes ) ) { $ nodes = [ $ nodes ] ; $ returnArray = false ; } $ result = [ ] ; foreach ( $ nodes as $ node ) { if ( $ node instanceof Element ) { $ node = $ node -> getNode ( ) ; } if ( ! $ node instanceof DOMNode ) { throw new InvalidArgumentException ( sprintf ( 'Argument 1 passed to %s must be an instance of %s\Element or DOMNode, %s given' , __METHOD__ , __NAMESPACE__ , ( is_object ( $ node ) ? get_class ( $ node ) : gettype ( $ node ) ) ) ) ; } Errors :: disable ( ) ; $ cloned = $ node -> cloneNode ( true ) ; $ newNode = $ this -> document -> importNode ( $ cloned , true ) ; $ result [ ] = $ this -> document -> appendChild ( $ newNode ) ; Errors :: restore ( ) ; } $ result = array_map ( function ( DOMNode $ node ) { return new Element ( $ node ) ; } , $ result ) ; return $ returnArray ? $ result : $ result [ 0 ] ; }
Adds a new child at the end of the children.

@param \DiDom\Element|\DOMNode|array $nodes The appended child

@return \DiDom\Element|\DiDom\Element[]

@throws \InvalidArgumentException if the passed argument is not an instance of \DOMNode or \DiDom\Element
Adds a new child at the end of the children .