Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find if node has siblings using simplexml

I am try to find if a certain node has siblings, and if it does, I would like to know what those siblings are.

Is this possible?

like image 861
Nic Hubbard Avatar asked Jan 23 '23 15:01

Nic Hubbard


1 Answers

In order to select a node's siblings, you have to use the corresponding XPath axe. Here is how to select all a node's siblings (ignoring the node itself)

$siblings = $node->xpath('preceding-sibling::* | following-sibling::*');

That's all you have to do.

like image 90
Josh Davis Avatar answered Feb 01 '23 02:02

Josh Davis