PHP Global Variables $GLOBALS
When you define a variable in global scope in PHP, you can sometimes have difficulty acccessing the variable from within another function call, if not explicity passe. Luckily, in PHP, the $GLOBALS variable holds all of our globally defined variables:
$myVar = 123; myFunction(); function myFunction() { echo $GLOBALS["myVar"]; //123 }
That said, the usual way to pass a variable to a function is as a parameter but $GLOBALS can be really helpful from time to time. Here is the equivalent:
$myVar = 123; myFunction($myVar); function myFunction($val) { echo $val; //123 }