PHP $Globals - PHP Global Variables



  • $GLOBALS is a PHP super global variable which is used to access global variables from anywhere in the PHP script (also from within functions or methods).
  • PHP stores all global variables in an array called $GLOBALS[index]. The index holds the name of the variable.
php-globals

Sample Code

<?php
$a = 26;
$b = 33;
function sum() {
  $GLOBALS['c'] = $GLOBALS['a'] + $GLOBALS['b'];
}
sum();
echo $c;
?>

Output

 59

Related Searches to PHP $Globals - PHP Global Variables