$x = 5;
function myFunc() {
global $x;
echo $x;
}Remeber that using globals usually isn't a good idea. Better idea would be divide your globals by categories/modules and store it in static variables of some classes.
PHP Coding tips & tricks. Function & error explanation, coding style, how tos etc. Short notes posted directly from developer work environment.
PHP Coding Tips
Showing posts with label global. Show all posts
Showing posts with label global. Show all posts
Tuesday, August 7, 2012
How to access global variable in php ?
If you are in a function on class method scope, you can gain access to a global variable by using a global keyword.
Subscribe to:
Posts (Atom)