Home  >  Article  >  Backend Development  >  php super global variables

php super global variables

巴扎黑
巴扎黑Original
2016-11-21 09:28:45855browse

Many predefined variables in PHP are "superglobal", which means they are available throughout the entire scope of a script. They can be accessed within a function or method without executing global $variable;.
These super global variables are:
$GLOBALS
$_SERVER
$_REQUEST
$_POST
$_GET
$_FILES
$_ENV
$_COOKIE
$_SESSION

$GLOBALS This kind of global variable is used in any PHP script Positional access to global variables (either from a function or method).
PHP stores all global variables in an array named $GLOBALS[index]. The name of the variable is the key of the array.

<?php 
$x = 75; 
$y = 25;
 
function addition() { 
  $GLOBALS[&#39;z&#39;] = $GLOBALS[&#39;x&#39;] + $GLOBALS[&#39;y&#39;]; 
}
 
addition(); 
echo $z; 
?>


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn