In reply to Alex Fung :
The following code doesn't work :
$x = 18;
$y = 6;
switch ($x) {
case (($y * 4) || (9 * 3)):
echo "Member";
break;
default:
echo "Not a member";
}
?>
Why :
want to test if $x == $y*4 or $x == 9*3 ($x == (($y*4)||(9*3))
However the case statement evaluate the value of (($y*4)||(9*3)) that is always true because 9*3=27 (!=0)
That's why this code always return true when $x != 0.
The correct code would be :
$x = 18;
$y = 6;
switch ($x) {
case (($y * 4)):
case ((9*3)):
echo "Member";
break;
default:
echo "Not a member";
}
?>
Boolean logic work inside case statement, you just need to know that the expression in the case statement is first evaluated then compared with the evaluated value in the switch statement.