PHP | DOMNode isSameNode() Function
Last Updated :
05 Mar, 2020
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
$dom = new DOMDocument();
$p_element = $dom ->createElementNS(
'my_namespace' , 'p' , 'GeeksforGeeks' );
$dom ->appendChild( $p_element );
$isSameNode = $dom ->isSameNode( $dom );
if ( $isSameNode ) {
echo 'Yes, $dom is same to itself.' ;
}
?>
|
Output:
Yes, $dom is same to itself.
Program 2:
<?php
$dom = new DOMDocument();
$p_element = $dom ->createElementNS(
'my_namespace' , 'p' , 'GeeksforGeeks' );
$dom ->appendChild( $p_element );
$dom2 = new DOMDocument();
$isSameNode = $dom ->isSameNode( $dom2 );
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
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...