How to demonstrate the use of $GLOBALS to access global variables in PHP | PHP program
Jun 24, 2021
PHP,
465 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());
?>