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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new DOMDocument
$dom = new DOMDocument();
  
// Create a paragraph element with a namespace
$p_element = $dom->createElementNS(
      'my_namespace', 'p', 'GeeksforGeeks');
  
// 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.';
}
?>

chevron_right


Output:

Yes, $dom is same to itself.

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create a new DOMDocument
$dom = new DOMDocument();
  
// Create a paragraph element with a namespace
$p_element = $dom->createElementNS(
      'my_namespace', 'p', 'GeeksforGeeks');
  
// 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.';
}
?>

chevron_right


Output:

No, $dom and $dom2 are different.

Reference: https://www.php.net/manual/en/domnode.issamenode.php




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.