OK, I'll try and clear this all up.
WHAT IS A FUNCTION?
A function performs a defined task, often one that is required to be performed more than once, and is initalised using a function call.
eg;
function helloWorld(){
echo "Hello World";
}
When called with;
helloWorld();
Will simply output 'Hello World' into the calling script.
However, if we wanted to perform a maths function, e.g add 1 to whatever was passed through a function we would;
function Increment($parameterIn)
{
$parameter = $parameterIn + 1;
return $parameter;
}
If we called that function, like so..
$parameter = "2";
$Incremented_parameter = Increment($parameter);
echo "$Incremented_parameter";
It would print out 3.
The return value, is passed to "$Incremented_parameter".
It is also good to remember the scope of the variables, whether they are global scope or function scope.
A function accepts COPIES of variables as paramters, no the actual variable, therefore if you did this;
function wontWork($myvariable){
$myvariable + 1;
}
then in the calling script,
you did
wontWork(4);
Nothing would happen and the value in the calling script would still be 4.
Think of a function of a separate program on its own, it knows nothing, you have to pass it something, let it do it's own job and give you something back.
Hope this helps