对于 PHP 中的 LINQ,我使用了 https://github.com/Athari/YaLinqo
我不知道如何在
where
子句中传递变量。
public function filter($arr, $find) {
Enumerable::from($arr)->where(function($val) { return stripos($val->item, $find) > -1; })->toArray();
}
似乎不起作用,就像未定义
$find
一样,但我将其作为方法的参数发送。
您可以使用
use
声明:
Enumerable::from($arr)
->where(function($val) use ($find) {
return stripos($val->item, $find) > -1;
})
->toArray();