note 79394 deleted from language.control-structures by felipe
| From: | felipe@php.net | Date: | Mon, 10 Dec 2007 18:37:11 +0000 |
| Subject: | note 79394 deleted from language.control-structures by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-133294@lists.php.net to get a copy of this message | ||
Note Submitter: Maurice R
----
In reply to fteng1 at gmail dot com (04-Aug-2007 06:48):
That's a horrible (and probably really slow) way to do that. Never use that! What you need to
use for this is the switch control operator.
<?php
switch( $year ) {
case 1948:
case 1960:
case 1972:
case 1984:
case 1996:
case 2008:
echo "Rat";
break;
case 1949:
case 1961:
case 1973:
case 1985:
case 1997:
case 2009:
echo "Ox";
break;
// etc...
}
?>
In your case PHP would first have to make arrays of the years (which means storing all the values in
it's memory) before checking each of these.
The switch control structure was specifically made for checks like these. For simpicity's and
speed's sake.