mysql - php Multiple Key Value Filter with an or statement

Solution:
The reason it is not working is because when you say:
'sex' => '1' or '0',
that gets interpreted an in-line conditional and you wind up with
'sex' => true,
If you want yourMultipleKeyValueFilter
to do what you want, you're going to have to change both your criteria array and your filter class. You'll want to pass something like:
'sex' => ['1', '0'], //1 and 0 are acceptable values
and rewrite your comparator to something like:
public function filter($item) {
foreach ($this->kvPairs as $key => $value) {
if(is_array($value) {
$match = false;
foreach($value as $v) {
$match = ($item[$key] === $v);
if($match) {
break; //If we find one match in our array, we can stop looking
}
}
} else {
$match = ($item[$key] === $value);
}
if(!$match) {
return false; //Any failure to match can stop immediately
}
}
return true; //If we get here, then we didn't fail to match any criteria
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: composer detected issues in your platform: your composer dependencies require a php version ">= 7.3.0".
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.