Forum Moderators: coopster
say for example i want to use a drop down menu with various options for someone to pick. If they pick say one out of 6 I want to echo different things for different things being picked. Can someone please help me
<?php
function carfactory($cars = "white rover") {
switch ($cars) {
case "mercedes":
$pricestr = " This will cost for $cars will be £450.33.\n"
break;
case "ford":
$pricestr = " Wow you really want a FORD?\n"
break;
case "white rover":
$pricestr = " Don't pick white.\n"
break;
}
return $pricestr;
}
echo carfactory();
echo carfactory("mercedes");
echo carfactory("ford");
?>
you can then add a case for each string you want to test for
function carfactory($cars) {
switch ($cars) {
case "mercedes":
$pricestr = " This will cost for $cars will be $450.33.\n" ;
break;
case "ford":
$pricestr = " Wow you really want a FORD?\n" ;
break;
case "white rover":
$pricestr = " Don't pick white.\n" ;
break;
}
return $pricestr;
}
echo carfactory($cars);
?>