Re: IF statement help
| From: | CC Zona | Date: | Fri, 28 Sep 2001 19:18:57 +0000 |
| Subject: | Re: IF statement help | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-69213@lists.php.net to get a copy of this message | ||
In article <Pine.LNX.4.33.0109281326310.13667-100000@oak.autus.lan>,
windon@orthus.net (Chesley A Windon) wrote:
> My question is: Is there a way to accomplish the same thing without having
> this large of an IF statement comparison?
>
> if (($key=="control1") || ($key=="control2") ||
> ($key=="control3") ||
> ($key=="control4") || ($key=="control5") ||
> ($key=="control6") ||
> ($key=="control7") || ($key=="control8") ||
> ($key=="control9")) {
>
> // do something;
>
> } else {
Someone else suggested a regex. If your values aren't as regex-friendly as
in the example implies, another alternative is a switch statement
<http://www.php.net/manual/en/control-structures.switch.php>.
switch($key) {
case "control1":
case "control2":
case "control3":
case "control4":
case "control5":
case "control6":
case "control7":
case "control8":
case "control9":
...
break;
default:
...
}
--
CC