I have few conditions there can be either 0 or more I want to go through the array if there are conditions and create a callback function that I will call in the filter and override one parameter
$f = function ($value) use ($array, $key) {
return in_array($value->{$key}, $array[$key]);
};
array_push(self::$conditions, $f);
I didn't think of anything better than putting all the conditions in an array and then pulling them out in a loop like this
public static function isPersonСorrespondsRequirements($people)
{
$result = true;
for($i = 0; $i < count(self::$conditions); $i++) {
$result &= self::$conditions[$i]($people);
};
return count(self::$conditions) > 0 ? $result : false;
}
in short, I want to get the result from the isPersonСorrespondsRequirements function, which will be compiled according to the conditions stored in the $conditions array and it will be called like this
$tmp = $array->filter(function ($value, $key) {
if (NeedMapper::isPersonСorrespondsRequirements($value)) {
return $value;
}
});
P.S. I work with laraver, cause function filter it is collection method