Re: ifelse/else
| From: | David Otton | Date: | Mon, 19 May 2003 12:57:10 +0000 |
| Subject: | Re: ifelse/else | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-148157@lists.php.net to get a copy of this message | ||
On 19 May 2003 08:03:52 -0400, you wrote:
>Speaking of switch, I've always wondered is it just a preference thing
>or are there situations were switch is more appropriate.
In switch()'s favour: fallthrough.
switch ($a) {
case 1 :
case 2 :
case 3 :
echo('0<$a<4');
break;
case 4 :
echo('$a == 4');
break;
default :
echo('$a is not in the range 0<$a<5');
}
Not a great usage example, but you get the idea.
if..elseif..else allows you to do this:
if ($a == 4) {
/* do stuff */
} elseif ($b == 7) {
/* do other stuff */
} elseif ($c == 'hello world') {
/* do other stuff */
} else {
/* catchall */
}
Though I wouldn't recommend it, it tends to produce hard-to-erad code.