Hey folks, this is a vanilla PHP-related question. A friend of mine is writing this switch statement to perform a basic logical operation and then output the result based on a working logic. But it seems like he ain't getting any accurate results. I tried to solve this simple problem but it also drove me crazy just like my friend.
[NOTE: WE ARE NOT DOING ANY FINANCIAL CALCULATIONS AND THIS CODE WON'T GO INTO PRODUCTION. IT's JUST BASIC PHP STUFF]
<?php
$val = 0;
switch ($val) {
case ($val >= 1 && $val !=
0):
echo "I have {$val} dollar only";
break;
case ($val < 1):
echo "I'm in debt :(";
break;
default:
echo "I'm totally broke :/";
}
?>
What he trying to do is:
He is checking the value of $val in the first case if it's above 1 and is not equal to 0. If the logic passes then echo out something and break. And I hope you've figured out the rest.
But the problem is, whenever I run the code after setting the value of $val equals to 0, I get this I have $0 only ... seems like the switch statement is not working as expected.
What have I done wrong here?