Forum Moderators: coopster
I later need to assign a numeric value to their choice, but rather than doing multiple ifs
if($Fruit == "apples")
{
$FruitValue = 120;
}
elseif ($Fruit == "oranges")
{
$FruitValue = 80;
}
etc
is there a way to do this in one go, without all the ifs?
$fruit = array("apples" => 120, "oranges" => 80);
$FruitValue = $fruit[$Fruit];
You might want to check to see if the index exists in the array before you actually do what I have shown above, but this should work out a little better for you.