I'm having trouble with a switch case conidtion.
Why in the following scenario:
$category = "A";
$offer = "none";
$discount = "none";
For the following code:
switch (TRUE) {
case ($category == 'A') : / #1
$msg = "hello";
case ($offer == 'special') : / #2
$id = "123";
case ($discount == '50D') : / #3
$id = "999";
break;
echo $id;
}
I get output of 999
for id
, even though #2
and #3
are not fullfilled?
EDIT:
Cases such as $offer == 'special'
are private cases of the general case which is $category == 'A'
.
That's why I want the function to go in this order.
if switch/case is not appropriate, what shall I use?