QueryPath\DOMQuery::siblings PHP Method

siblings() public method

This will compile a list of every sibling of every element in the current list of elements. Note that if two siblings are present in the DOMQuery object to begin with, then both will be returned in the matched set, since they are siblings of each other. In other words,if the matches contain a and b, and a and b are siblings of each other, than running siblings will return a set that contains both a and b.
See also: contents()
See also: children()
See also: parent()
See also: parents()
public siblings ( string $selector = null )
$selector string If the optional selector is provided, siblings will be filtered through this expression.
    public function siblings($selector = null)
    {
        $found = new \SplObjectStorage();
        foreach ($this->matches as $m) {
            $parent = $m->parentNode;
            foreach ($parent->childNodes as $n) {
                if ($n->nodeType == XML_ELEMENT_NODE && $n !== $m) {
                    $found->attach($n);
                }
            }
        }
        if (empty($selector)) {
            return $this->inst($found, null, $this->options);
        } else {
            return $this->inst($found, null, $this->options)->filter($selector);
        }
    }