This article mainly introduces the invocation of PHP in the difference between the value and the reference, has a certain reference value, now share to everyone, the need for friends can refer to
PHP Transfer Value : Within the scope of the function, changing the value of a variable is not likely to affect the values of the variables outside the function.
PHP by reference : Within the scope of the function, any change to the value is also reflected outside the function, because the pass-through refers to the memory address.
Daniel's Explanation:
Pass value : Same as copy. "For example, I have a Yikanghuayuan house, I give you building materials, you built a root of my house the same house, you do nothing in your house will affect me, I do in my house do not affect you, independent of each other." "
[PHP] view plain copy
<?php $testa =1; Define variable a $testb =2; Define variable b $testb = $testa; Variable a assigns a value to the variable B echo $testb; Display as 1 ?>
reference : similar to the C language of the pointer, feel the same. For example, I have a Yikanghuayuan house, I give you a key, two of us can enter this House, what you do in the House will affect me.
[PHP] view plain copy
<?php $param 2=1; Define variables 2 $param 1 = & $param 2; Pass a reference to variable 2 to the variable 1 echo $param 2; Shown as 1 $param 1 = 2; Assign 2 to the variable 1 echo $param 2; Display as 2 ?>
"Pros and Cons:" It takes time to pass a value, especially for large strings and objects, which can be a costly operation, delivering a reference, and any operation within a function is equivalent to the operation of a transfer variable, and high efficiency when transferring large variables!
Reprint please specify the source https://blog.csdn.net/qq_28194557/article/details/70543753
Related recommendations:
An explanation of anonymous and closure functions in PHP