Preface:
in PHP, "=" is an assignment symbol, a deep copy for a normal variable, and a shallow copy for an object (the assignment of an object is a reference assignment).
Note: When an object is passed as a parameter, it is also a reference pass, regardless of whether the function defines a & symbol before the argument.
Briefly:
* Deep Copy: Assignment value is fully copied, full copy, change to one of them, does not affect the other. (Has been imitated, can also surpass.) * Shallow copy: When assigned, the reference assignment is equivalent to taking an alias. One of the modifications will affect the other. (Destiny Community, a proud, a loss of loss)
Practice:
1. Realization of the deep copy of common variables
The realization of the deep copy of the common variable $a= ' Zhangsan '; $b = $a; echo $a. " \ r \ n "Echo $b." \ r \ n "; $b =" Lisi "; Echo $a." \ r \ n "Echo $b." \ r \ n ";/** * Output Results *zhangsan *zhangsan * *zhangsan *lisi **/
Conclusion: The assignment of a normal variable is a deep copy
2. realization of shallow copy of common variable
The realization of shallow copy of ordinary variable $c= "Wangwu"; $d =& $c; Echo $c. " \ r \ n "Echo $d." \ r \ n "; echo" \ r \ \ "$d =" xiaoer "; Echo $c." \ r \ n "Echo $d." \ r \ n ";/** output Results *wangwu *wangwu * *xiaoer *xiaoer **/
Conclusion: The assignment of a normal variable is a deep copy
Brief analysis of PHP shallow copy and deep copy