PHP $GLOBALS superglobal

PHP $GLOBALS
  • $GLOBALS is a PHP super global variable which is used to access global variables from anywhere in the PHP script.
  • PHP stores all global variables in an array called $GLOBALS[name_of_variable].


  • example
  • <!DOCTYPE html>
    <html>
    <body>
    <?php
    $welcome = "PHP Coders";
    function welcome() {
    $var = "phpcoderspoint.com";
    echo "Hello ". $GLOBALS["welcome"] .", welcome to ".$var;
    }
    welcome();
    ?>
    </body>
    </html>