Switch Statement: Multiple Values
Posted: Mon Nov 07, 2005 12:23 am
I've been learning php for a while now and really enjoying it. The only thing I would like to know is how to use (if possible) multiple values for a switch statement. I'm used to Visual Basic's Selelect statement. In VB I could do this:
How would one do this in PHP?
As far as I can see one would either need to use IF...ELSEIF statements or do something like this:
This seems like a bit of a time consumer.
Is there a way to do this properly in PHP?
Code: Select all
Select var$
case is < 20
'do something
case 20
'do something specific
case is > 20
'do something else
end selectAs far as I can see one would either need to use IF...ELSEIF statements or do something like this:
Code: Select all
switch ($var){
case 0:
case 1:
case 2:
...
case 19
//do something
case 20:
//do something specific
case 21:
case 22:
case 23:
...
case 30:
//do something else
}Is there a way to do this properly in PHP?