Superglobal $GLOBALS

This is a super USEFUL superglobal which helps you to access not-global VARIABLES everywhere in your code as far code is connected with files using INCLUDE function.

Let’s say you want to access a normal VARIABLE outside of a function.


    $num = 100; // normal variables can't be accessed within a function without the help from $GLOBALS

    function database() {

        echo $GLOBALS['num']; // using $GLOBALS you can access a variable outside of the function

        $GLOBALS['num'] = 120;

        echo $GLOBALS['num']; // this superglobals can also be REDEFINED, in this example both $num will be echoed out. By changing value of $num it's value afterwards will also be changed.
    }

    database(); // by executing this function $num with a value of '100' will be accessed and echoed out.

    echo $num;