Send variable to where clause LINQ PHP

For LINQ in PHP, I used https://github.com/Athari/YaLinqo

I do not know how to pass the variable to where.

public function filter($arr, $find) {
   Enumerable::from($arr)->where(function($val) { return stripos($val->item, $find) > -1; })->toArray();
}

It does not seem to work as it is $findnot defined, but I am sending it as a method parameter.

+4
source share
1 answer

You can use the operator use:

Enumerable::from($arr)
  ->where(function($val) use ($find) {
    return stripos($val->item, $find) > -1; 
  })
  ->toArray();
+1
source

Source: https://habr.com/ru/post/1691448/


All Articles