我有以下代码
$newsheadline = array();
$crawler->filter('p.title > a')->each(function ($node) {
array_push($newsheadline, htmlentities($node->text()));
});
这给了我警告
array_push() expects parameter 1 to be array, null given
变量作用域:$newsheadline
对您的闭包不可用,因此您需要use
它...而且由于您正在对闭包进行修改,因此您还需要通过引用传递它
$crawler->filter('p.title > a')->each(
function ($node) use (&$newsheadline) {
array_push($newsheadline, htmlentities($node->text()));
}
);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句