w3resource logo


PHP $GLOBALS (super global) variable

PHP $GLOBALS (super global) variable

Secondary Nav

Description

$GLOBAL is a php super global variable which can be used instead of 'global' keyword to access variables from global scope, i.e. the variables which can be accessed from anywhere in a php script even within functions or methods.

Here is an example to testify the theory mentioned above:  

<?php
$s = 25;
$t = 50;
function subtraction()
{
$GLOBALS['v'] = $GLOBALS['t'] - $GLOBALS['s'];
} 
subtraction();
echo $v;
?> 

In the code above, since v is a variable present within $GLOBALS array, it is accessible form outside the function also.

View the example of $GLOBALS variable in the browser



Is this content useful for you?

 


You might be using Adblocker. Since w3resource does not charge anything from users, all of our expenses (e.g. Hosting, Content Creation, Development etc.) are met by advertisement. Please whitelist w3resource.