Php programmers are familiar with the term process. Php engineers generally do not have a deep understanding of object-oriented, so they need to call external variables in methods in a large process, therefore, there will be many opportunities for using global variables. I will explain how to use global variables for the users in the input line, "global variables", the global word in this term tells us that this variable can be used everywhere. let's look at an example first:
The code is as follows:
$ A = 1;
$ B = 2;
Function Sum ()
{
Global $ a, $ B; // declare it as a global variable
$ B = $ a + $ B;
}
Sum ();
Echo $ B;
?>
Result: 3
If no global variable is available, the values $ a and $ B cannot be obtained in the method. therefore, to use an external variable in the method, you must declare this variable as a global variable first, this is convenient.