Re: [PHP4BETA] Is this a good idea for an operator?

From: Date: Wed, 04 Aug 1999 04:44:00 +0000
Subject: Re: [PHP4BETA] Is this a good idea for an operator?
References: 1  Groups: php.version4 
Request: Send a blank email to php-version4+get-3090@lists.php.net to get a copy of this message
> switch($action) { > case "modify": > case "create": > case "delete": > blah blah; > } What if you want to work with arrays (possible dynamically created)? This construct wont work with that. I worked up a simple little function to check if a value was in an array, but it would become quite complex to make it use the && operator or similar. function isInArray($value, $ary) { for ($i_val = 0; $i_val < count($ary); $i_val++) { if ($value == $ary[$i_elem]) { return true; } } return false; } Then I just call the function: if (isInArray($action, array("update", "delete", "add", "etc.."))) { echo "It's in there!"; } else { echo "Not there"; } It would be nice if something like this were built in, but not at all neccessary. -Dan > To me this is the cleanest way to do this and it is infinitely flexible in > that you have a built-in negated case by adding a default case, and even > the matching cases can trigger slightly different bits of code. The whole > point of the switch statement is to cleanup up long and complex if > statements just like that.

« previous php.version4 (#3090) next »