Trouble with creating my first function
Posted: Mon Jun 02, 2008 4:31 pm
First off, I am new to programming in PHP. I am having trouble creating these if statements to functions. i am not getting the passing of variables to and from within functions. If any one can help me put these if statements to functions or explain to me how to pass the variables that would be great. Thanks for future help
Code: Select all
$city_or_town = "town";
$townnamelength = 9;
$is_student = "n";
function cityTown(
if ($city_or_town=="town")
{
$cost = $townnamelength * 5000;
}
else
{
$cost = $townnamelength * 7000;
}
if ($is_student == "Y")
{
$studentPercentOff = $cost *.10;
$studentPrice = $cost - $studentPercentOff;
echo $studentPrice;
}
else {
echo $cost;
}