Is there a way to include multiple cases inside a switch method in php?
A:
Yes it is possible
Here is an example to start with
<?
$i = 1;
$j = 10;
switch($i) {
case "2":
echo "The value is 2";
break;
case ($i==1 && $j==10):
echo "Your exceptional Switch case is triggered";
break;
default:
echo "Invalid";
break;
}
?>
Starx
2010-06-07 07:59:14
Mark Baker
2010-06-07 08:57:54
Mark Baker
2010-06-07 09:08:27
+1
A:
What's wrong with simply nesting switches?
$i = 1;
$j = 10;
switch($i) {
case 2:
echo "The value is 2";
break;
case 1:
switch($j) {
case 10:
echo "Exception Case";
break;
default:
echo "The value is 1";
break;
}
break;
default:
echo "Invalid";
break;
}
Mark Baker
2010-06-07 09:54:51
Read my comments about starx example.... it doesn't actually work correctly
Mark Baker
2010-06-07 12:05:38