php引述&

WBOY
Release: 2016-06-13 13:02:09
Original
813 people have browsed it

php引用&

php引用&的意思

?

如:

function &test()
{
static $b=0;//申明一个静态变量
$b=$b+1;
echo $b;
return $b;
}


?$a=&test();? //&代表引用函数这样,test()返回的$b和$a指向了相同的地址。也可以说$a就是$b.修改任意一个,另一个也会随着变化 。 这里输出1

?$a=5;? //这里$a=5,刚$b也等于5.因为上面$a=&test()是地址引用。
?test(); //因为这里将输出6.

?

例2.

$a=123;

$b=&$a;

$b=321;

echo $a;

//和上面例子道理是一样的,输出321.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template