Just follow through the script. 🙂
Well, we start out with, $a = 1, and $b = 2;
Then a function is defined.
Sum(); -- then the function is called.
$a then has the value of 1.
$b has the value of 3.
And then you print out the value of $b.
Because in the function the value of $a and $b are global, the value of the main $a and $b are changed.
So instead of the original values of:
$a = 1;
$b = 2;
It is now:
$a = 1;
$b = 3;
If the function was this (without the global vars):
<?php
$a = 1;
$b = 2;
function Sum()
{
$b = $a + $b;
}
Sum();
echo $b;
?>
The values of $a = 1 and $b =2.
The reason is that the function did NOT change the value of $b. It only changes a LOCAL copy of the variable inside the function Sum(), but not outside of it.
I hope this is understandable. If you have anymore questions, feel free to ask. 🙂