<?php
function setGlobalVariable() {
$GLOBALS['variable_name'] = "Some Value";
}
setGlobalVariable();
echo $variable_name;
// Outputs: Some Value
$GLOBALS['a'] = 'localhost';
function body(){
echo $GLOBALS['a'];
}
<?php
$myVariable = "a";
function changeVar($newVar) {
global $myVariable
$myVariable = "b";
}
echo $myVariable; // Should echo b
?>
$a = 1;
$b = 2;
function Sum(){
global $a, $b; // allows access to vars outside of function
$b = $a + $b;
}
Sum();
echo $b; // output is 3
$GLOBALS["foo"]