Re: [PHP] switch with multiple case
Same as C switch($something) { case "this": do that;break; case "those":case "them": do other; break ... default: print error } Cheers -- Phil Driscoll Dial Solutions +44 (0)113 294 5112 http://www.dialsolutions.com http://www.dtonline.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] switch with multiple case
switch($something) { case "this": do this; break; case "those": case "them": do other; break; case "crap": case "doesn't matter": case "whatever": do nothing; break; default: print error; } 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. . Christian Dechery (lemming) . http://www.tanamesa.com.br . Gaita-L Owner / Web Developer -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] switch with multiple case
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]