- the commands "Case" *must* be written lower case
- if multiple case-groups, followed by a default:, and no case matches the select-value, the last case is executed, the default: is ignored. Test:
Code: Select all
$x = 'a';
Switch ($x) {
case 'b':
Echo 'b!';
Break;
case 'c':
Echo 'c!';
Break;
case "d":
Echo 'd!';
Break;
default:
Echo 'Other!';
}
By the way: I wouldn't call the "operands" of the cases "labels" - I'd name them values. This would fit much more the comparison to IF/ELSEIF/ELSE: they are just values, too.
So I'd write:
Code: Select all
switch (value) {
case value1;
code to be executed if value=value1;
break;
...
...
default:
executed if no case matches value
}