Re: else if vs switch

From: Date: Mon, 18 Jun 2012 00:11:17 +0000
Subject: Re: else if vs switch
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-318270@lists.php.net to get a copy of this message
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

« previous php.general (#318270) next »