Its possible to use global variables declared in one fu开发者_运维技巧nction into an another function in php?
Yes.
function func_A () {
global $var;
$var = 5;
}
function func_B () {
global $var;
echo $var;
}
func_A();
func_B();
echoes 5.
What happens when you use the global
keyword is, PHP makes a note that the variable name you gave refers to that variable name in the global scope (whether or not that variable exists in the global scope at that time).
Use of global functions should be avoided where possible, as they can lead to functions having side-effects.
edit: I mean "global variables", not "global functions".
Yes, see PHP Manual - Variable scope - The global keyword
精彩评论