Symfony\Component\DomCrawler\Crawler::evaluate PHP Method

evaluate() public method

Since an XPath expression might evaluate to either a simple type or a \DOMNodeList, this method will return either an array of simple types or a new Crawler instance.
public evaluate ( string $xpath ) : array | Crawler
$xpath string An XPath expression
return array | Crawler An array of evaluation results or a new Crawler instance
    public function evaluate($xpath)
    {
        if (null === $this->document) {
            throw new \LogicException('Cannot evaluate the expression on an uninitialized crawler.');
        }
        $data = array();
        $domxpath = $this->createDOMXPath($this->document, $this->findNamespacePrefixes($xpath));
        foreach ($this->nodes as $node) {
            $data[] = $domxpath->evaluate($xpath, $node);
        }
        if (isset($data[0]) && $data[0] instanceof \DOMNodeList) {
            return $this->createSubCrawler($data);
        }
        return $data;
    }