How can global arrays like $_GLOBALS be used effectively in PHP scripts?
Global arrays like $_GLOBALS can be used effectively in PHP scripts to store and access global variables across different scopes. This can be useful for sharing data between different parts of a script or between different scripts. However, it is important to use these global arrays judiciously and avoid over-reliance on them to prevent potential naming conflicts or security vulnerabilities.
// Example of using $_GLOBALS to store and access global variables
$_GLOBALS['global_var'] = "Hello, world!";
function display_global_var() {
echo $_GLOBALS['global_var'];
}
display_global_var(); // Output: Hello, world!