PHP运算子=&意思是?

编程入门 行业动态 更新时间:2024-10-21 20:43:35
本文介绍了PHP运算子=&意思是?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

可能重复: "=&"是什么意思和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; // 13

Artefacto在评论中指出,$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运算子=&意思是?

本文发布于:2023-10-14 22:20:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492379.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:PHP   amp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!