You are here

public function Crawler::reduce in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/dom-crawler/Crawler.php \Symfony\Component\DomCrawler\Crawler::reduce()

Reduces the list of nodes by calling an anonymous function.

To remove a node from the list, the anonymous function must return false.

Parameters

\Closure $closure An anonymous function:

Return value

Crawler A Crawler instance with the selected nodes.

File

vendor/symfony/dom-crawler/Crawler.php, line 385

Class

Crawler
Crawler eases navigation of a list of \DOMElement objects.

Namespace

Symfony\Component\DomCrawler

Code

public function reduce(\Closure $closure) {
  $nodes = array();
  foreach ($this as $i => $node) {
    if (false !== $closure($this
      ->createSubCrawler($node), $i)) {
      $nodes[] = $node;
    }
  }
  return $this
    ->createSubCrawler($nodes);
}