Superglobals means variables that are predefined variables in PHP which means that are always accessible. Below are some examples of the PHP superglobals variables.
The PHP superglobal variables are:
PHP stores all global variables in an array called $GLOBALS[index]. The index holds the name of the variable.
The example:-
The PHP superglobal variables are:
- $GLOBALS
- $_SERVER
- $_REQUEST
- $_POST
- $_GET
- $_FILES
- $_ENV
- $_COOKIE
- $_SESSION
$GLOBALS
$GLOBALS is a PHP superglobal variable that is used to access global variables from anywhere in the PHP script.PHP stores all global variables in an array called $GLOBALS[index]. The index holds the name of the variable.
The example:-
<?php
$x = 75;
$y = 25;
function addition() {
$GLOBALS['z'] = $GLOBALS['x'] + $GLOBALS['y'];
}
addition();
echo $z;
?>
$x = 75;
$y = 25;
function addition() {
$GLOBALS['z'] = $GLOBALS['x'] + $GLOBALS['y'];
}
addition();
echo $z;
?>
output are:-100
Hope you like this post...In the next post, I will explain all the remaining PHP superglobals variables.
0 Comments