PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
gxpark
Forum Commoner
Posts: 33 Joined: Fri Jun 21, 2002 4:01 pm
Location: Mexico City
Post
by gxpark » Sat Jun 22, 2002 5:11 pm
Hi,
Is it somehow possible to specify several options for a single case inside a switch block? Like this (which doesn't work):
Code: Select all
switch ($something) {
case $this or $thisone or $eventhis:
//do something
default:
//do other stuff
}
I hope I don't need to write an individual case for each option...
Thanks in advance.
will
Forum Contributor
Posts: 120 Joined: Fri Jun 21, 2002 9:38 am
Location: Memphis, TN
Post
by will » Sat Jun 22, 2002 5:27 pm
yes... a case statement will slip down to the next one until there is a break statement, so this would do the trick....
Code: Select all
switch($test)
{
case'a':
case'b':
case'c':
// do something for cases a-c
break;
case'd':
// do something for case d
break;
}
gxpark
Forum Commoner
Posts: 33 Joined: Fri Jun 21, 2002 4:01 pm
Location: Mexico City
Post
by gxpark » Sat Jun 22, 2002 5:32 pm
Oh yes, I forgot I read that in the manual. Thanks for reminding me!