In the php7 local variables, global variables, and differences over global variable usage

我们在使用php函数得时候遇到 ,局部变量,全局变量,超全局变量,如何灵活运用,php7中之局部变量,全局变量,超全局变量用法和区别?

    1,局部变量

        局部变量是在函数体内得变量,不能用外部得变量得值,只有当局部变量得值定义为全局变量才能使用外部变量得值

    $a=1

    function jj()
 {
    echo $a;
 }

 jj();

 2.全局变量

申明在函数外得变量,可以全局使用,使用关键词 global 

//global $a;
$a=“www.96net.com.cn”;
function aj(){
//global $a;
echo $a;
}

and ();

3, superglobals

$GLOBALS
$_SERVER
$_REQUEST
$_POST
$_GET
$_FILES
$_ENV
$_COOKIE
$_SESSION

Guess you like

Origin blog.51cto.com/13959155/2456708