PHP赋值运算符=& [英] PHP assignment operator =&

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

问题描述

可能重复:
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屋!

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