PHP中的引用赋值运算符==& [英] Reference assignment operator in PHP, =&

查看:100
本文介绍了PHP中的引用赋值运算符==&的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

=&(等于和号)赋值运算符在PHP中做什么?

What does the =& (equals-ampersand) assignment operator do in PHP?

已弃用吗?

推荐答案

它不被弃用,也不太可能被弃用.例如,这是一种标准方法,可以对一个数组或对象镜像进行更改,而对另一数组进行更改,而不是复制现有数据.

It's not deprecated and is unlikely to be. It's the standard way to, for example, make part of one array or object mirror changes made to another, instead of copying the existing data.

它称为按引用分配,引用手册

It's called assignment by reference, which, to quote the manual, "means that both variables end up pointing at the same data, and nothing is copied anywhere".

The only thing that is deprecated with =& is "assigning the result of new by reference" in PHP 5, which might be the source of any confusion. new is automatically assigned by reference, so & is redundant/deprecated in$o = &new C;, but not in $o = &$c;.

由于难以搜索,请注意=&(等于和号)与= &(等于空格和号)相同,并且通常这样写:它会遇到其他变量,例如$x = &$y['z'];$x = &$someVar(<和>美元符号变量名称).从文档简化的示例:

Since it's hard to search, note that =& (equals ampersand) is the same as = & (equals space ampersand) and is often written such that it runs into the other variable like $x = &$y['z']; or $x = &$someVar (ampersand dollar sign variable name). Example simplified from the docs:

$a = 3;
$b = &$a;
$a = 4;
print "$b"; // prints 4


这是指向按引用分配上的详细部分的便捷链接.在PHP手册中.该页面是有关参考文献的系列的一部分-值得花一点时间阅读整个系列.


Here's a handy link to a detailed section on Assign By Reference in the PHP manual. That page is part of a series on references - it's worth taking a minute to read the whole series.

这篇关于PHP中的引用赋值运算符==&amp;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆