How to use $GLOBALS variable in php to access global variables
Access global variable in php via any function/class using $GLOBALS inside, outside of scope.
Php $GLOBALS variable is used to retrieve any already declared global variable because inside php scripting programming language there are all global variables defines in $GLOBALS[index] form, So if you define any global variable in php then it will automatically set into index value and can be call through $GLOBALS[index_value] . So here is the complete step by step tutorial for How to use $GLOBALS variable in php to access global variables.
How to use $GLOBALS variable in php to access global variables.
Code for globals-variables.php file.
<!doctype html> <html> <head> <meta charset="utf-8"> <title>$GLOBALS variable in php to access global variables</title> </head> <body> <?php $a = 20; $b = 30; function sum() { //ACCESSING VARIABLES USING GLOBALS $GLOBALS['c'] = $GLOBALS['a'] + $GLOBALS['b']; } sum(); echo $c; ?> </body> </html>
Screenshot:
Comments
Post a Comment