Re: switch statement

From: Date: Thu, 17 Oct 2002 22:15:22 +0000
Subject: Re: switch statement
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-120414@lists.php.net to get a copy of this message
You can probably do this faster with an array... $cars = array( 'BMW' => array(165 => '8L'), 'Mercedes' => array(150 => '5L'), 'Ford' => array(135 => '6L'), 'Chevy' => array(135 => '6L'), 'Dodge' => array(135 => '6L'), 'Default' => '4L' ); $var = (isset($cars[$carname][$speed]) ? $cars[$carname][$speed] : $cars['Default']); This is just one way to do it though... -js benc@cox.net wrote:
I am using a switch statement and want to have the user put in a car type and speed of the car then have the statement give it a variable $var which is a engine type. However, I want to minimize some of the work and have the car companies that have the same engine type be in an array. Is this possible. If so, what is wrong with my switch statement. switch ($carname AND $speed) { case $carname==BMW AND $speed==165: ($var= "8L"); break; case $carname==Mercedes AND $speed==150: ($var= "5L"); break; case $carname=array( "Ford", "Chevy", "Dodge" ) AND $speed==135: ($var= "6L"); break; default: ($var= "4L"); } Please help. Ben


« previous php.general (#120414) next »