Re: multiple cases in switch statement
| From: | Matthew Ballard | Date: | Thu, 21 Dec 2000 22:31:57 +0000 |
| Subject: | Re: multiple cases in switch statement | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-4585@lists.php.net to get a copy of this message | ||
When you want to include multiple possible cases, you don't use ||, just do:
switch ($num) {
case "1st":
case 1:
do stuff;
break;
case "2nd":
case 2:
do stuff;
break;
default:
do stuff;
break;
};
Each case is only supposed to do one check, and essentially only an == check, and once a true case is found, it will run all the code under it in the switch state until it hits the end or a break.
Matthew
At 05:04 PM 12/21/2000 -0500, you wrote:
Hello all... I'm running a little address checker and attempting to catch ordinal numbers (first, second, third, etc) by catching multiple instances such as 1st or 1 gives us FIRST so far I have this... the worst part about it is that part of this is working and the rest is not... when I enter "1" or "1ST" into it, I get FIRST back... when I enter "2ND" or "2" I get nothing back (not even the default no error, no nothin)... when I enter "3RD" I get THIRD back... When I enter "4TH" or "4" I get nothing back (not even the default no error, no nothin)...if ( eregi ( "[0-9]{1,2}([a-zA-Z])*" ,$num ) ) { //echo "hit the switch"; switch ($num) { case ("1ST" || "1"): $street .= "FIRST"; break; case ("2ND" || "2"): $street .= "SECOND"; break; case "3RD": $street .= "THIRD"; break; case ("4TH" || "4"): $street .= "FOURTH"; break; default: $street .= $num; break; }echo $street;Any suggestions on what I'm missing here? What's makes this very weird for me is that the first case WORKS... --------------------- John Asendorf - jasendorf@lcounty.com Web Applications Developer http://www.lcounty.com - NEW FEATURES ADDED DAILY! Licking County, Ohio, USA 740-349-3631 The benefit to the government of replacing all $1 Federal Reserve notes with $1 coins would be $522.2 million per year, according to estimates of the General Accouting Office released on April 7, 2000. -- PHP Windows Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-windows-unsubscribe@lists.php.net For additional commands, e-mail: php-windows-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net