Accessing Global Variables in PHP


Use $GLOBALS array to access global variables inside functions.

Source Code

$GLOBALS['varName'] = "Global variable";
function test() {
    echo $GLOBALS['varName'];
}
test();
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments