Re: Switch Question

From: Date: Mon, 24 Feb 2003 23:14:41 +0000
Subject: Re: Switch Question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-137007@lists.php.net to get a copy of this message
To do this you would use multiple nested case statments and break only after the last case statement. You cannot use conditionals within a case statement but this has the effect of an OR condition... switch($color) { case "black": case 1: return ImageColorAllocate($image,0,0,0); break; //.. etc.. // } Hope that helps. - Kevin ----- Original Message ----- From: "Van Andel, Robbert" <RVanAndel@chartercom.com> To: <php-general@lists.php.net> Sent: Monday, February 24, 2003 3:48 PM Subject: [PHP] Switch Question I'm trying to make a switch statement that looks for more than one possible value. Something similar to: switch($color) { case "black" || "1": return ImageColorAllocate($image,0,0,0); break; case "white" || "2": return ImageColorAllocate($image,255,255,255); break; case "gray" || "3": return ImageColorAllocate($image,200,200,200); break; } This is not working however, since all my colors are now black (it worked before I add the number portion of the case statement. First off, is this even possible to do, or do I need to make a seperate case for the numbers. If it is possible, how do I make it work? Robbert van Andel

« previous php.general (#137007) next »