I know PHP uses lazy-evaluation / short-circuit operators. But say I wanted to evaluate all the expressions in a condition, for example:
$a = "Apple";
$b = "Banana";
$c = "Cherry";
function check($fruit) {
if ($fruit != "Banana") {
echo "$fruit is good.
";
return true;
} else {
echo "$fruit is bad.
";
return false;
}
}
if (check($a) && check($b) && check($c)) {
echo "Yummy!
";
}
Because of lazy-evaluation, this will only output:
Apple is good.
Banana is bad.
Rather than the desired output of:
Apple is good.
Banana is bad.
Cherry is good.
This is useful in form validation for instance.
So my question: Is there any way to force all expressions in a condition to be evaluated in PHP, and if not, what would be the best/quickest way to get the desired result in the example above?