Re: multiple cases in switch statement
| From: | Mark Maggelet | Date: | Thu, 21 Dec 2000 22:42:01 +0000 |
| Subject: | Re: multiple cases in switch statement | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-4587@lists.php.net to get a copy of this message | ||
On Thu, 21 Dec 2000 17:04:49 -0500, Asendorf, John
(jasendorf@lcounty.com) 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"):
this line will evaluate to either "case 1:" or "case true:"
what you really want to do is something like this:
switch($num){
case "1ST": case "1": $street .= "FIRST"; break;
case "2ND": case "2": $street .= "SECOND"; break;
...
}
- Mark