Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony-DomCrawler_Php_Symfony_Domcrawler - Fatal编程技术网

Php Symfony-DomCrawler

Php Symfony-DomCrawler,php,symfony,domcrawler,Php,Symfony,Domcrawler,我在Symfony中使用DomCrawler $variable = 'value'; $crawler->filter('table > tr')->each( function ($node, $i) { // $variable; } ); 我试图访问函数中的变量,但得到错误:未定义变量 如何在函数内部调用此变量?您需要使用use语句从父范围注入变量: $variable = 'value'; $crawler->filter('t

我在Symfony中使用DomCrawler

$variable = 'value';
$crawler->filter('table > tr')->each(
    function ($node, $i) {
        // $variable;
    }
);
我试图访问函数中的变量,但得到错误:未定义变量


如何在函数内部调用此变量?

您需要使用
use
语句从父范围注入变量:

$variable = 'value';
$crawler->filter('table > tr')->each(
     function ($node, $i) use ($variable) {
           // $variable;
     }
);

您需要使用
use
语句从父范围注入var:

$variable = 'value';
$crawler->filter('table > tr')->each(
     function ($node, $i) use ($variable) {
           // $variable;
     }
);

谢谢@Michael SivolobovThanks@Michael SivolobovPlease阅读。请阅读。