可能重复: "=&"是什么意思和PHP中的& =运算符是什么意思?
我找到了运算符"=&"在下面的代码中,我不知道这意味着什么.它是什么意思,它是做什么的?
I found the operator "=&" in the following code, and I do not know what it means. What does it mean and what does it do?
我阅读的代码:
function ContentParseRoute($segments) { $vars = array(); //Get the active menu item $menu =& JSite::getMenu(); $item =& $menu->getActive(); // Count route segments $count = count($segments); ....推荐答案
这不是引用(&)的赋值(=).
This isn't an assignment (=) by reference (&).
如果您要说的话:
$a = 42; $b =& $a;您实际上是在说 将$a 通过引用分配给$b.
You are actually saying assign $a by reference to $b.
通过引用分配的作用是将两个变量绑定"在一起.现在,如果您以后要修改$a,$b将会随之更改.
What assigning by reference does is "tie" the two variables together. Now, if you were to modify $a later on, $b would change with it.
例如:
$a = 42; $b =& $a; //later echo $a; // 42 echo $b; // 42 $a = 13; echo $a; // 13 echo $b; // 13Artefacto在评论中指出,$a =& $b与$a = (&$b) 不同.
As Artefacto points out in the comments, $a =& $b is not the same as $a = (&$b).
这是因为虽然&运算符表示从某事物中进行引用,但=运算符确实按值进行赋值,所以表达式$a = (&$b)表示进行临时引用到$b,然后将该临时变量的值分配给$a,而不是按引用分配.
This is because while the & operator means make a reference out of something, the = operator does assign-by-value, so the expression $a = (&$b) means make a temporary reference to $b, then assign the value of that temporary to $a, which is not assign-by-reference.
更多推荐
PHP运算子=&意思是?
发布评论