Php variable access does not understand PHPcode & lt ;? Php $ my_var & quot; abc & quot; functionmy_fun () {echo $ my_var;} my_fun ();? & Gt; why can't I access the variable inside the function? the variable inside the function is the global variable outside the local variable function. it is reasonable to say that the variable outside the function can be accessed inside the function. Why can't I understand the function's php variable access? help
PHP code
Why can't variables outside the function be accessed inside the function?
The variable in the function is a local variable.
The global variables outside the function are supposed to be able to access the variables outside the function.
Why does the function prompt the local variable $ my_var may not have been initialized?
Thank you for your help!
------ Solution --------------------
Why cannot I access the variables outside the function? you can ask the global variables outside the function,
The variable in the function is a local variable.
The global variables outside the function are supposed to be accessible inside the function.
Why does the function prompt the local variable $ my_var may not have been initialized?
Thank you for your help!
$ My_var = "abc ";
Global $ my_var = "abc ";
------ Solution --------------------
Global $ my_var;
$ My_var = "abc ";
Discussion
Reference:
Why cannot I access the variables outside the function? you can ask the global variables outside the function,
The variable in the function is a local variable.
The global variables outside the function are supposed to be accessible inside the function.
Why does the function prompt the local variable $ my_var may not have been initialized?
Could you help me explain this ......
------ Solution --------------------
PHP code
------ Solution --------------------
As you can understand, there are two worlds inside and outside the function, and the time variables in both worlds are unknown by default. only the introduction gives you the opportunity to understand them. The Introduction method is global.
PHP code
------ Solution --------------------
To be set to a global variable,
------ Solution --------------------
I tested the code that was sent out after the test was successful.
Discussion
Reference:
PHP code
Global $ my_var;
$ My_var = 'abc ';
Function my_fun (){
Global $ my_var;
Echo $ my_var;
}
My_fun ();
?>
Global $ my_var in the second line; is it useless?
------ Solution --------------------
In front of the variable outside the function + global cannot afford to use
The variable outside the function is a global variable. + global is useless.
The global variable is added to the variables in the function. this design is for easy differentiation and understanding. Besides, the examples in this manual are very clear.
Http://www.php.net/manual/zh/language.variables.scope.php
------ Solution --------------------
------ Solution --------------------
$ A = 'abc ';
Function aaa (){
Echo $ a; // you can write $ GLOBALS ['A'] or global $ a on this statement;
}
?>