The amount is divided into global variables and local variables. Children who have learned the C language know that the scope of the global variable is the entire file. It works even inside the function, but in PHP, if you use a global variable in a function, PHP will assume that the variable is undefined. If we need to use this global variable inside the function, then we need to add the keyword Global to the inside of the function, before the global variable. Here is a small demo of your own. To prove what I said.
<?php $str = "string"; function test () { if (isset ($STR)) { echo "the string is defined"; } else { echo "the string is undefined"; } } Test ();? >
This is the result of running in the browser:
<?php $str = "string"; function test () { global $str;//The above test function does not have this sentence if (isset ($STR)) { echo "the string is Defined "; } else { echo "the string is undefined"; } } Test ();? >
This is the result of running in the browser: