Sna*_*yes 5 php linq anonymous-function yalinqo
对于 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();
}
Run Code Online (Sandbox Code Playgroud)
似乎没有像$find
未定义那样工作,但我将它作为方法的参数发送。
您可以使用use
声明:
Enumerable::from($arr)
->where(function($val) use ($find) {
return stripos($val->item, $find) > -1;
})
->toArray();
Run Code Online (Sandbox Code Playgroud)