$GLOBALS — references all variables available in the global scope

$GLOBALS This global variable is used to access global variables anywhere in a PHP script (either from a function or a method).

PHP stores all global variables in an array named $GLOBALS[index]. The names of the variables are the keys of the array.

The following example shows how to use the super global variable $GLOBALS:

 

 

 

<?php
$x = 75;
$y = 25;
 
function addition() {
  $ GLOBALS ['z'] = $ GLOBALS ['x'] + $ GLOBALS ['y'];
}
 
addition();
echo $z; //100
?>



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324783127&siteId=291194637