Home > Article > Backend Development > Detailed explanation of php reference assignment
Reference assignment is to copy the reference of variable (the new reference still points to the original value). After the parameters are truly passed by address, the line parameters and actual parameters are the same object, but their names are different. Modification of the line parameters will affect the value of the actual parameters
The & symbol indicates that the value is assigned by reference during the assignment process.
For example: It reminds me of the pointers I learnedC language when I was in college, and it feels almost the same. For example, I have a house. If I give you a key, both of us can enter the house. Whatever you do in the house will affect me.
table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy4119')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy4119>$aa=1; $bb=2; $aa=&$bb;//$bb引用内容指向$aa,不管$aa,或者$bb发生变化,彼此都会变化 $aa=3; echo $aa,'--',$bb;//输出3--3 </td> </tr> </table></td> </tr> </table>
The above is the detailed content of Detailed explanation of php reference assignment. For more information, please follow other related articles on the PHP Chinese website!