Php understands that the scope of a variable refers to the scope that a variable can be used or visible in a script. php has six basic scope rules. 1. the built-in Super global variables can be used and visible anywhere in the script. 2. constants can be globally visible once declared; that is, they can be used both inside and outside the function. 3. declare in a script that php understands the scope of variables
Scope refers to the range in which a variable in a script can be used or visible. php has six basic scope rules.
1. the built-in Super global variables can be used and visible anywhere in the script.
2. constants can be globally visible once declared; that is, they can be used both inside and outside the function.
3. The global variables declared in a script are visible throughout the script, but not within the function.
4. when the variable used in the function is declared as a global variable, its name must be consistent with the global variable name.
5. variables created inside the function and declared as static cannot be visible outside the function, but this value can be kept during multiple function executions.
6. the variable created in the function is local to the function. when the function is terminated, the variable does not exist.
$ _ GET and $ _ POST arrays and some other special variables have their own scope rules. These are called Super global variables that can be used and visible anywhere, including internal and external functions.