1

I am trying to use some Goutte code :

$oldtext='';
// Get the latest post in this category and display the titles
$crawler->filter('h2 > a')->each(function ($node) {
    print $node->text()."\n";
    $oldtext=$node->text();
    print $oldtext."\n";
});

I have 2 questions :

  1. what does statement "function ($node)" it's kind of inline function definition
  2. why $oldtext variable it's not presistent ? it's like inside of "function ($node)" all variables are reinitiated
Daniel D
  • 79
  • 1
  • 4
  • It is a [closure function](https://www.php.net/manual/en/functions.anonymous.php). Change `function ($node) {` to `function ($node) use (&$oldtext){` to make it persistent across calls. – nice_dev Dec 19 '21 at 06:26

0 Answers0