PHP赋值运算符=& [英] PHP assignment operator =&
问题描述
可能重复:
中的引用赋值运算符
php =&
=& 赋值运算符在PHP中是什么意思?我在作业部分的PHP手册中找不到任何参考.
我在类实例化中看到了它,所以我完全不理解 =& 和单独的 = 有什么区别.
这表示引用分配./p>
=
和=&
之间有两个区别.
首先,=
不会创建参考集:
$a = 1;
$b = $a;
$a = 5; //$b is still 1
另一方面,=&
运算符确实会创建参考集:
$a = 1;
$b = &$a;
$a = 5; //$b is also 5
第二,=
更改参考集中所有变量的值,而&=
中断参考集中.将此示例与之前的示例进行比较:
$a = 1;
$b = &$a;
$c = 5;
$a = &$c; //$a is 5, $b is 1
Possible Duplicate:
Reference assignment operator in php =&
What does the =& assignment operator mean in PHP? I could not find any reference in PHP Manual in assignment section.
I saw it in a class instantiation, so I quite don't understand what's the difference between =& and solely =.
It means reference assignment.
There are two differences between =
and =&
.
First, =
does not create reference sets:
$a = 1;
$b = $a;
$a = 5; //$b is still 1
On the other hand, the =&
operator does create reference sets:
$a = 1;
$b = &$a;
$a = 5; //$b is also 5
Second, =
changes the value of all variables in the reference set, while &=
breaks the reference set. Compare the example before with this:
$a = 1;
$b = &$a;
$c = 5;
$a = &$c; //$a is 5, $b is 1
这篇关于PHP赋值运算符=&的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!