Nodes Traversable - ThomasWeinert/FluentDOM GitHub Wiki

FluentDOM\Nodes Traversable

FluentDOM\Nodes implements the Traversable interface. More specific it implements IteratorAggregate.

The returned iterator is an recursive iterator. You can iterate the found nodes and their children.

Usage

$xml = <<<XML
<html>
<body>
  <p>Hello</p>
  <p>cruel</p>
  <p>World</p>
</body>
</html>
XML;

foreach (FluentDOM($xml)->find('//p') as $key => $value) {
  echo $key, ': ', $value, "\n";
}

Output

0: Hello
1: cruel
2: World
⚠️ **GitHub.com Fallback** ⚠️