This is probably a general PHP question more than a Kirby question.
I’m doing a bunch of filtering via some AJAX calls. One of these filters is to check if any one of several parameters are found in a field. (example: each book has a region, I want to filter all books that are either north_america
or europe
or latin_america
.
Here is a condensed version:
function contains($str, array $arr) {
foreach($arr as $a) {
if (stripos($str,$a) !== false) return true;
}
return false;
}
foreach ($params as $param => $param_array) {
switch($param) {
case "regions":
$books = $books->filter(function($book) { // this line!!
if (contains((string)$book->collections(), $param_array)) {
return $book;
}
});
break;
...
how can I pass $param_array
into the filter function?
$books = $books->filter(function($book, $param_array) {
gives me an error:
Warning: Missing argument 2 for {closure}()
Is this a scope thing? or an array vs not-array thing?