What is the $GLOBALS superglobal in PHP?

  • An array containing references to all variables that are currently defined in the global scope of the script.
  • A variable that stores global values for a PHP script.
  • A special function for accessing global variables.
  • A reserved keyword for declaring global variables.
The correct option is 1. The $GLOBALS superglobal in PHP is an associative array that contains references to all variables that are currently defined in the global scope of the script. The keys of the $GLOBALS array are the variable names, and the values are references to the corresponding variables. It provides a way to access global variables from anywhere within the script, including within functions or classes, without having to use the global keyword. By accessing the $GLOBALS superglobal, you can retrieve and manipulate global variables as needed. However, it is generally recommended to use global variables sparingly and follow good coding practices to avoid potential issues. Learn more: https://www.php.net/manual/en/reserved.variables.globals.php
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *