Re: else if vs switch

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


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@xxxxxxxxx> 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@xxxxxxxxxx',
...
);

...

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



[PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [Find Someone]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux