/////////////////////////////////////////////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 '

Task 4: A



'; $MyName = 'John Smith'; Echo '$MyName = '. $MyName; Echo '
Calling SayHello using by value.
'; say_hello($MyName); Echo '

'; Echo 'Check if $MyName is still the same value:
'; Echo '$MyName = '. $MyName .'

'; Echo 'Calling SayHello2 using by Reference.
'; say_hello2($MyName); Echo '

'; Echo 'Check if $MyName is still the same value:
'; Echo '$MyName = '. $MyName .'

'; /////////////////////////////////////////////Task 4 B ///////////////////////////////////////// Echo '

Task 4: B



'; Echo 'Global TotalSum or $GLOBALS['. "'TotalSum'] = ". $GLOBALS['TotalSum']; Echo '

'; AddValue(5); Echo 'Global TotalSum or $GLOBALS['. "'TotalSum'] = ". $GLOBALS['TotalSum']; Echo '

'; AddValue(10); Echo 'Global TotalSum or $GLOBALS['. "'TotalSum'] = ". $GLOBALS['TotalSum']; Echo '

'; AddValue(5); Echo 'Global TotalSum or $GLOBALS['. "'TotalSum'] = ". $GLOBALS['TotalSum']; Echo '

';