Re: switch statement
| From: | Foldenyi Tamas | Date: | Thu, 17 Oct 2002 22:23:42 +0000 |
| Subject: | Re: switch statement | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-120416@lists.php.net to get a copy of this message | ||
Try this:
$x = array(
'BMW' => array('165' => '8L'),
'Mercedes' => array('150' => '5L')
)
foreach(array("Ford", "Chevy", "Dodge") as $v)
$x[$v]['135']='6L';
if (isset($x[$carname][$speed]))
$var = $x[$carname][$speed];
else
$var = "4L";
echo $var;
> 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");
> }