Re: [PHP] Two cases going to same case?
At 5:18 AM -0400 6/30/02, Leif K-Brooks wrote: I have a switch in a script I'm working on. I need to have case 1 and 2 both to to case 3, but without case 1 going through case 2. Is this possible? No, but you can do it this way: switch ($foo) { case 1: ... do_something(); break; case 2: ... do_something(); break; case 3: do_something(); break; } function do_something() { # this is the stuff that you want to do that is common to your # cases 1, 2 and 3 } This accomplishes the same thing. -steve -- ++ | Steve Edberg [EMAIL PROTECTED] | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | ++ | The end to politics as usual: | | The Monster Raving Loony Party (http://www.omrlp.com/) | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Two cases going to same case?
Hi One way to achieve the same effect: fallthru = 0; switch($whatever){ case 1: do something1; $fallthru = 1; case 2: if(!$fallthrough){ do something2; } case 3 do something3; break; } Tom At 05:18 AM 30/06/2002 -0400, Leif K-Brooks wrote: I have a switch in a script I'm working on. I need to have case 1 and 2 both to to case 3, but without case 1 going through case 2. Is this possible? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Two cases going to same case?
Leif K-Brooks wrote: I have a switch in a script I'm working on. I need to have case 1 and 2 both to to case 3, but without case 1 going through case 2. Is this possible? Does case 3 have to be in the switch? If not, just leave it to execute just after the end of the switch. Otherwise, consider making your program modular. For case 3, include a file that has the code you're wanting to execute. Then all you have to do is include the same file at the bottom of both cases 1 and 2. Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php