$GLOBALS in PHP
The $GLOBALS
array is a superglobal that contains all global variables in PHP. It allows you to access global variables from anywhere in your script.
Example of Using $GLOBALS
<?php
$x = 10;
$y = 20;
function sum() {
return $GLOBALS['x'] + $GLOBALS['y'];
}
echo sum(); // Outputs: 30
?>
Output:
30
Explanation: This example demonstrates how to use the $GLOBALS
array to access global variables within a function.