Home > Backend Development > PHP Tutorial > Detailed explanation of php reference assignment

Detailed explanation of php reference assignment

怪我咯
Release: 2023-03-14 06:42:01
Original
1571 people have browsed it

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(&#39;copy4119&#39;)">复制代码</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,&#39;--&#39;,$bb;//输出3--3
</td> </tr> </table></td> </tr> </table>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template