Access a global variable in a PHP function

前端 未结 9 2013
感动是毒
感动是毒 2020-11-29 05:33

According to the most programming languages scope rules, I can access variables that are defined outside of functions inside them, but why doesn\'t this code work?



        
9条回答
  •  感动是毒
    2020-11-29 06:27

    For many years I have always used this format:

    
    

    I find it straightforward and easy to follow. The $GLOBALS is how PHP lets you reference a global variable. If you have used things like $_SERVER, $_POST, etc. then you have reference a global variable without knowing it.

提交回复
热议问题