Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Crawler.php

function Crawler::each

Calls an anonymous function on each node of the list.

The anonymous function receives the position and the node wrapped in a Crawler instance as arguments.

Example:

$crawler->filter('h1')->each(function ($node, $i) { return $node->text(); });

Parameters

\Closure $closure An anonymous function:

Return value

array An array of values returned by the anonymous function

File

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

Class

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

Namespace

Symfony\Component\DomCrawler

Code

public function each(\Closure $closure) : array {
    $data = [];
    foreach ($this->nodes as $i => $node) {
        $data[] = $closure($this->createSubCrawler($node), $i);
    }
    return $data;
}
RSS feed
Powered by Drupal