Help Me/Question Php Global Variable

justiinn

Well-Known Member
php is very useful in making interactive web pages. superglobals are predefined variables that is you can use it any time whenever required.it was introduced in version 4.1.0.it is denoted by$.
there are different types of global variables-$globals,$server,$request,$cookie etc..
i dont know its use and cant use it in my codes.
will you explain me?
 

RADHESHYAM GUPTA

White Belt
There are so many predefined variable in Php, All predefined variable is known as super global variable.
It means it access from anywhere in php program such as out of class, out of function.
Here some Super global variable examples:-

  • $_GLOBAL
  • $_GET
  • $_POST
  • $_FILES
  • $_COOKIE
<?php
$a = 20;
$b = 15;
function addition() {
$GLOBALS['c'] = $GLOBALS['a'] + $GLOBALS['b'];
}
addition();
echo $c;
?>
 
Top