Accessing Global Variables

$GLOBALS[s] provides a means to manipulate global variables directly in functions.

<!DOCTYPE html>
<html>
<head></head>
<body><?php

function f(){
   $v=1;
   echo $v;                      // 1, local variable
   echo $GLOBALS['v'];    // 2, global variable
   $GLOBALS['w']=3;
   unset($GLOBALS['v']);  // global variables can now be unset
}
$v=2;
f();
echo $w;  // 3, global variable
echo $v;   // Notice, already unset

?> </body>
</html>

123 Warning: Undefined variable $v in D:\xampp\htdocs\contents\processed\en\php\global-variables.php on line 16