分配变量时,"="和"=&"之间有什么区别?

Fly*_*Cat 4 php variables operators assignment-operator

我想弄清楚$a=&$b和之间的区别$a=$b.我知道&将变量作为参考变量.但是下面的测试给了我相同的结果.有人可以解释这个区别吗?谢谢.

 $a=5;
 $b=6;

 $a=&$b;
 echo $a; //6


 $a=5;
 $b=6;

 $a=$b;
 echo $a; //6
Run Code Online (Sandbox Code Playgroud)

Wri*_*ken 13

首先:你几乎不需要参考,如果可以的话,避免使用它们的混乱.

$a=5;    //assign value to a
$b=&$a;  //make $b a reference to $a
$b=6;    //assigning a value to $b assigns the same value to $a (as they point to the same location
echo $a; //6


$a=5;    //assign a value to a
$b=$a;   //set $b to the value of $a
$b=6;    //set $b to another value leaves $a at it's original value
echo $a; //5
Run Code Online (Sandbox Code Playgroud)