Re: switch with multiple case

From: Date: Wed, 14 Mar 2001 15:12:29 +0000
Subject: Re: switch with multiple case
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-43849@lists.php.net to get a copy of this message
> In ASP, you can have something like: > > <snip> > <% > select case something > case "this" do that > case "those","them" do other > case "crap","doesn't matter","whatever" do nothing > case else print error > end select > %> > </snip> > > IN PHP you can't do cases like that, because like in C, u must have a > constant, not a list of them. > Is there anyway to get pass this? Doing a case for each thing even tough it > does the exact same thing as 10 others is going to get a little stupid code. > ____________________________ Is this what you want? <?php switch ($val) { case 'this': // do that break; case 'those': case 'them': // do that break; case 'crap': case 'doesnt matter': case 'whatever': break; // do nothing default: print('error'); break; } ?> BTW, this works C/C++. Regards, Yasuo Ohgaki

« previous php.general (#43849) next »