I have code something like this:
<?
$a="localhost";
function body(){
global $a;
echo $a;
}
function head(){
global $a;
echo $a;
}
function footer(){
global $a;
echo $a;
}
?>
is there any way to define the global variable in one place and make the variable $a
accessible in all the functions at once? without making use of global $a;
more?
The
$GLOBALS
array can be used instead:From the Manual:
If you have a set of functions that need some common variables, a class with properties may be a good choice instead of a global: