Skip to content
Thomas Weinert edited this page Jul 29, 2014 · 2 revisions

FluentDOM\Nodes::index()

int index([ NULL|string|\DOMNode|\Traversable $selector = NULL ]);

The function has two modes. If a $selector is provided. It searches for that element in the internal list and returns it index.

If the $selector is NULL it returns the index of the first node from the internal list in its parent elements child nodes list.

Usage

$xml = <<<'XML'
<items>
  <item>One</item>
  <item>Two</item>
  <item>Three</item>
</items>
XML;

echo FluentDOM($xml)
  ->find('//item[contains(.,"Two")]')
  ->index();

Output

1
Clone this wiki locally