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

FluentDOM\Nodes::end()

FluentDOM\Nodes end();

Traversing methods like FluentDOM\Nodes::find() return a new instance, but store the parent instance. FluentDOM\Nodes::end() returns that parent or itself if it is the top of a chain.

Usage

$fd = new FluentDOM\Nodes(
  '<items><item/><item/><item/></items>'
);
echo $fd
  ->find('/items')
  ->find('item')
  ->each(
    function($node, $index) {
      $node['index'] = $index;
    }
  )
  ->end()
  ->each(
    function($node, $index) {
      $node['length'] = count($node);
    }
  );

Output

<?xml version="1.0"?>
<items length="3"><item index="0"/><item index="1"/><item index="2"/></items>
Clone this wiki locally