Hello,everyone.im new here and im green hand now.Thanks for ur replies!! i have write a php program. <?php $a=1; function qq(){ $a=4; global $a ; } qq(); echo $a; ?> PHP: i donno why the program would echo out 1 . i think the program would echo out 4,because the global $a is after the $a=4 Thanks for ur replies!!
thank u.i just want to know why i make $a into global in the qq function,but the $a outside the funciton be globaled.
in face ,there r 2 $a in the program,one is outside the function and one is in it,when i make the $a global,which $a would be globaled??
Don't think of it as "making it global", think of it as "from now on, when I refer to $a, I want to be using the $a in the global namespace".
The $a outside the function is in your global scope. To access variables inside a function (without passing them as argument), you need to use global before this variable is being used. Not sure if that made sense to you, however, you might want to have a look at the official manual page which explains it better. www.php.net/global