--- title: Walk::walk --- Walk::walk — Output generator for walking down the DOM tree ## Description ##
public Walk::walk ( \Closure|null $filter = null ) : \Generator
Non-standard. Creates a [`\Generator`](https://www.php.net/manual/en/class.generator.php) object for walking down the DOM tree. This is in lieu of recreating the awful [DOM TreeWalker API](https://developer.mozilla.org/en-US/docs/Web/API/Treewalker). ## Examples ## **Example \#1 Print name of every Element** ```php loadHTML('Ook!

Eek

'); $tree = $dom->walk(function($node) { return ($node instanceof Element); }); foreach ($tree as $t) { echo "{$t->nodeName}\n"; } ?> ``` The above example will output something similar to: ```php html head title body h1 ```