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!
function add($numOne, $numTwo) {
$val = $numOne + $numTwo; }
In the parameter list, that's in brackets, why are those there? If they weren't there wouldn't the variables be passed in from outside of the function anyway?
Are you confusing global scoped variables with local-scoped variables?
The names in the function declaration are the names used locally inside the function. If they were defined globally (outside the function) they would need to be declared global inside the function.
$num1 = 10;
$num2 = 2;
function add()
{
global $num1, $num2;
return $num1 + $num2;
}
echo add(); //12 (yuck! - don't do this!)
Anything passed in as an argument will be assigned to that local variable in the first example so you know what's going on regardless of the environment around the function.