Trouble with creating my first function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jgonzalez14
Forum Newbie
Posts: 1
Joined: Mon Jun 02, 2008 4:25 pm

Trouble with creating my first function

Post 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;
            }
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Re: Trouble with creating my first function

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