Re: else if vs switch

From: Date: Fri, 15 Jun 2012 22:29:47 +0000
Subject: Re: else if vs switch
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-318253@lists.php.net to get a copy of this message
Way easier to just use a map. $mapping = array( 'Calgary' => "abc@emailaddress", 'Brooks' => "def@emailaddress", // etc ); $toaddress = $mapping[$city]; Regards, –Josh ____________________________________ Joshua Kehn | @joshkehn http://joshuakehn.com On Jun 15, 2012, at 6:20 PM, April Mains wrote: > I have 25 cities and am currently using the following to set the $toaddress for submitting > student pre-registration forms based on the city selected: > > if ($city == "Calgary") { > $toaddress = "abc@emailaddress"; > } elseif ($city == "Brooks") { > $toaddress = "def@emailaddress"; > > and so on. > > > Would using switch statements like the following make any appreciable difference? > > switch ($city) { > case"Calgary": > $toaddress = "abc@emailaddress"; > break; > case"Brooks": > $toaddress = "def@emailaddress"; > break; > > and so on. > > Is there a more elegant solution? > > Thank you for your help, > > April > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.general (#318253) next »