PHP | DOMNode isSameNode() Function

The DOMNode::isSameNode() function is an inbuilt function in PHP which indicates if two nodes are the same node or not.
Syntax:
bool DOMNode::isSameNode( DOMNode $node )
Parameters: This function accepts a single parameter $node which holds the node to be compared.
Return Value: This function returns TRUE on success or FALSE on failure.
Below given programs illustrate the DOMNode::isSameNode() function in PHP:
Program 1:
<?php   // Create a new DOMDocument $dom = new DOMDocument();   // Create a paragraph element with a namespace $p_element = $dom->createElementNS(       'my_namespace', 'p', 'zambiatek');   // Append the child to DOMDocument $dom->appendChild($p_element);   // Check if the node is same $isSameNode = $dom->isSameNode($dom);   // Check if the namespace is default or not if($isSameNode) {     echo 'Yes, $dom is same to itself.'; } ?> |
Output:
Yes, $dom is same to itself.
Program 2:
<?php   // Create a new DOMDocument $dom = new DOMDocument();   // Create a paragraph element with a namespace $p_element = $dom->createElementNS(       'my_namespace', 'p', 'zambiatek');   // Append the child to DOMDocument $dom->appendChild($p_element);   // Create another new DOMDocument instance $dom2 = new DOMDocument();   // Check if nodes are same $isSameNode = $dom->isSameNode($dom2);   // Check if the namespace is default or not if(!$isSameNode) {     echo 'No, $dom and $dom2 are different.'; } ?> |
Output:
No, $dom and $dom2 are different.
Reference: https://www.php.net/manual/en/domnode.issamenode.php



