PDA

Click to See Complete Forum and Search --> : switch statement [Resolved]


ober0330
Feb 25th, 2004, 01:43 PM
can you have multiple values in one case?

case "1,2,3":

kows
Feb 25th, 2004, 02:08 PM
try

$chk = "blahblah";
$var = "ooga";
$var2 = "booga";
switch($chk){
case ($var || $var2):
echo "wiggy waggy woo";
break;
default:
echo "default";
}

phpman
Feb 26th, 2004, 04:02 PM
you can't do that


working a bit around with it I found out that it is not possible to
compare the variable with two different values in one step like this
(system running a w2k server, apache2.0.43 & php430):
switch ($myvar) {
case ("foo" || "bar"): //do something
break;
case ("other"): //do another thing
break;
default:
}
rather use:
switch ($myvar) {
case ("foo"):
case ("bar"): //do something
break;
case ("other"): //do another thing
break;
default:
}

ober0330
Feb 27th, 2004, 07:08 AM
Yeah, I actually used that instead. Falling through without breaks seems like the best method.