Below is a basic example of passing variables with functions. I hope this will explain the ways in which to do it. TRY not to use global variables.
function dosomething($first,&$second,$third=0)
{
echo "first=" . $first . "<br />"; // pass variable
echo "second=" . $second . "<br />"; // pass variable, and alterations change original
echo "third=" . $third . "<br />"; // pass third, default to 0 if not passed
$first =$first + 10;
$second=$second + 10;
$third =$third + 10;
return TRUE; // not necessary but usefull if need to check if function was successful
}
$a = 50;
$b = 60;
echo "a=" . $a . "<br />";
echo "b=" . $b . "<br />";
dosomething($a,$b);
echo "a=" . $a . "<br />";
echo "b=" . $b . "<br />";
first is called pass by value : a copy of the variable (value) is passed into the function, you can alter the value within the function without it changing the original value.
second is pass by reference : the location of the variable is passed to the function, so any changes made to this change the original as well.
third is a pass by value but it also has a default if it is omitted when called. Usefull for extending the functionality of a function while still keeping the code simple.
e.g.
function welcomemessage($name,$heading="Welcome"

{
echo $heading . " " . $name . "<br />";
}
welcomemessage("John"

;
// gives 'Welcome John'
welcomemessage("John","Greetings);
// gives 'Greetings John'
I try and put the variables with default values at the end of the list, because it is easier to read and understand the call. ie dosomthingelse($a,,,,,"rr",,,) - yuck!!