Page 1 of 1

Trouble with creating my first function

Posted: Mon Jun 02, 2008 4:31 pm
by jgonzalez14
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;
            }

Re: Trouble with creating my first function

Posted: Mon Jun 02, 2008 5:00 pm
by panic!
this format is like this..

Code: Select all

 
 
function functionname($varableshere)
{
 
return $avalue;
 
}
 
 
so for example:
 
function myfunction($variable1,$variable2)
 
{
 
return $variable1+$variable2;
 
 
}
 
 
print myFunction(3,2);