php函数名前添加& 函数的引用返回

function &test(){
	static $b=0;
	$b= $b+1;
	return $b;
}
$a= test();
echo $a,"\n";
$a = 3;
$a= test();
echo $a,"\n";


$a = &test();
echo $a,"\n";
$a= 10;
$a= test();
echo $a,"\n";

 结果:

test()函数引用返回就是   $a 引用$b   同一个内存地址区域   因此改变$a的值  $b的值同时改变  结果改变

static静态局部变量  不会随着函数的调用(调用过程中不操作)和退出而发生改变   调用结束该变量继续存在但是不能使用它;  不能用表达式初始化静态变量

静态全局变量   只能在定义它的文件中使用  不能在其它文件中调用   即static限定了它的作用域。

猜你喜欢

转载自www.cnblogs.com/yongbuyanhui/p/9556067.html