/////////////////////////////////////////////Task 4 /////////////////////////////////////////
//This variable is Global because it is declared outside of any functions.
//Thus all functions can access it using the $GLOBALS array.
$TotalSum = 0;
function AddValue($value){
//This variable even though have the same name
//as the variable in global is still local thus any
//changes made to it would not affect the global variable.
//and it is also not accessable outside of this function.
$TotalSum = 23;
echo "AddValue Local variable TotalSum = $TotalSum";
echo "
";
echo 'Global TotalSum or $GLOBALS['. "'TotalSum'] = ". $GLOBALS['TotalSum'];
echo "
";
echo "Adding $value to the global TotalSum Variable.";
echo "
";
$GLOBALS['TotalSum'] += $value;
}
function say_hello($it){
//The variable $it is received by value thus nothing that
//happens in the function can change the original value.
echo ' Hello, '. $it;
$it = 'I am no longer '. $it;
}
function say_hello2(&$it){
//The variable &$it is received by reference thus all changes made to &$it that
//happens in the function will change the original value.
echo ' Hello, '. $it;
$it = 'I am no longer '. $it;
}
/////////////////////////////////////////////Task 4 A /////////////////////////////////////////
Echo '