DOMDocumentFragment::prepend
PHP function
Edit on GitHub ✎
(PHP 8)
Prepends nodes before the first child node
Description
DOMDocumentFragment::prepend(DOMNode|string ...$nodes): void
Prepends one or many nodes to the list of children before the first child node.
Examples
DOMDocumentFragment::prepend example
Prepends nodes before the fragment root.
php
<?php
$doc = new DOMDocument;
$fragment = $doc->createDocumentFragment();
$fragment->appendChild($doc->createElement("world"));
$fragment->prepend($doc->createElement("hello"), "beautiful");
echo $doc->saveXML($fragment);
?>The above example will output:
output
<hello/>beautiful<world/>See Also
DOMParentNode::prependDOMDocumentFragment::append