How to demonstrate the use of $GLOBALS to access global variables in PHP | PHP program
Feb 28, 2022
PHP,
2058 Views
How to demonstrate the use of $GLOBALS to access global variables in PHP | PHP program
How to demonstrate the use of $GLOBALS to access global variables in PHP | PHP program
We will create a global variable and access the global variable using $GLOBALS.
<?php
$num = 30;
function sumNumber()
{
$num = 20;
$res = 0;
$res = $GLOBALS['num'] + $num;
return $res;
}
printf("Sum is: %d<br>", sumNumber());
?>