I am new to php so I do not know much about $_GLOBALS. I expect these are used to access global variables anywhere. So, my question is what is the problem inside function addition()
, why I cannot do this? Can't I directly assign a value to the variable z.
<?php
$x = 75;
$y = 25;
function addition () {
$z = $GLOBALS['x'] + $GLOBALS['y'];
}
addition();
echo $z;
?>
I get following error:
Notice: Undefined variable: z in C:\xampp\htdocs\php\first.php on line 14
which is echo $z;