FluentDOM\Nodes::index PHP Méthode

index() public méthode

Search for a given element from among the matched elements.
public index ( null | string | DOMNode | Traversable $selector = NULL ) : integer
$selector null | string | DOMNode | Traversable
Résultat integer
    public function index($selector = NULL)
    {
        if (count($this->_nodes) > 0) {
            if (NULL === $selector) {
                return $this->xpath('count(
              preceding-sibling::node()[
                self::* or (self::text() and normalize-space(.) != "")
              ]
            )', $this->_nodes[0]);
            } else {
                $callback = $this->getSelectorCallback($selector);
                foreach ($this->_nodes as $index => $node) {
                    if ($callback($node)) {
                        return $index;
                    }
                }
            }
        }
        return -1;
    }