Re: else if vs switch
| From: | James | Date: | Mon, 18 Jun 2012 01:41:01 +0000 |
| Subject: | Re: else if vs switch | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-318271@lists.php.net to get a copy of this message | ||
Same logical check with my personal preference ;)
$toaddress = $mapping['default'];
if ( isset($city) && isset($mapping[$city]) ) { ... }
--
Sent from my Android phone with K-9 Mail. Please excuse my brevity.
Jim Lucas <lists@cmsws.com> wrote:
On 6/15/2012 3:29 PM, Joshua Kehn wrote:
> Way easier to just use a map.
>
> $mapping = array(
> 'Calgary' => "abc@emailaddress",
> 'Brooks' => "def@emailaddress",
> // etc
> );
> $toaddress = $mapping[$city];
I would use this, but add a check to it.
$mapping = array(
'default' => 'default@domain.tld',
...
);
...
if ( isset($mapping[$city]) ) {
$toaddress = $mapping[$city];
} else {
$toaddress = $mapping['default'];
}
Jim
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php