What is the difference between “GLOBAL” and “STATIC” variable in PHP?

前端 未结 4 1762
眼角桃花
眼角桃花 2021-01-02 10:29

What exactly is the difference between the GLOBAL and STATIC variables in PHP? And which one is preferable to use, when we want to use a variable in multiple functions?

4条回答
  •  伪装坚强ぢ
    2021-01-02 11:14

    Global is used to get the global vars which may be defined in other scripts, or not in the same scope.

    e.g.

    Static is used to define an var which has whole script life, and init only once.

    e.g.

提交回复
热议问题