Forum Moderators: coopster

Message Too Old, No Replies

please help with function

         

Flolondon

6:26 pm on Apr 5, 2006 (gmt 0)

10+ Year Member



<?php
function carfactory($cars = "white rover")
{
return " This will cost for $cars will be £450.33.\n";
}
echo carfactory();
echo carfactory("mercedes");
echo carfactory("ford");
?>

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

jatar_k

7:39 pm on Apr 5, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



<?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

Flolondon

1:35 am on Apr 6, 2006 (gmt 0)

10+ Year Member



thanks jatar... i will try that out...

Flolondon

1:58 am on Apr 6, 2006 (gmt 0)

10+ Year Member



Parse error: syntax error, unexpected T_BREAK in C:\aasdf.php on line 159

jatar... I tried it and thats the error it gave me.

Flolondon

2:08 am on Apr 6, 2006 (gmt 0)

10+ Year Member



all i want to do please is echo the one that is being picked by the user

gettopreacherman

3:39 pm on Apr 7, 2006 (gmt 0)

10+ Year Member



<?php

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);

?>

Flolondon

12:58 pm on Apr 8, 2006 (gmt 0)

10+ Year Member



thanks i will try it out. thanks