Is there an elegant way to check if multiple, but not all, conditions are true from any given number of conditions?
For example, I have three variables: $ a, $ b and $ c. I want to check that all two of them are correct. So the following:
$a = true; $b = false; $c = true;
But this is not so:
$a = false; $b = false; $c = true;
In addition, I can check if 4 out of 7 conditions were true.
I understand that I can check each combination, but this will become more complicated as the number of conditions increases. Penetrating through conditions and keeping the count is the best option I can think of, but I thought there might be another way to do this.
Thanks!
Edit: Thanks for all the great answers, they are very much appreciated. Just to put a wrench on the job, what if the variables were not explicit logical? For instance.
($a == 2) ($b != "cheese") ($c !== false) ($d instanceof SomeClass)
source share