The General data type (int, float, bool) does not explain this.
Here is a detailed description of the difference between an array and the object of a class as a parameter for value passing
Array value passing
Instance code:
<?php function Main () { $cc = array ( ' A ', ' B ' ); Change ($CC); Var_dump ($CC); Die;} function Change ($CC) { $cc = array (' DD ');} Main ();? >
output:
array(2) {
[0]=>
string
(1)
"a"
[1]=>
string
(1)
"b"
}
Array reference passing
<?php function Main () { $cc = array ( ' A ', ' B ' ); Change ($CC); Var_dump ($CC); Die;} Function Change (& $CC) { $cc = array (' DD ');} Main ();? >
Outpout:array (1) { [0]=> string (2) "DD"}
Class Object Value passing
<?phpclass pp{public $ss = 0;} function Main () { $p = new pp (); Change ($p); Var_dump ($p); Die;} function Change ($p) { $p->ss = 10;} Main ();? >
Output:object (PP) #1 (1) { ["ss"]=> Int (10)}
Class object reference passing
<?phpclass pp{public $ss = 0;} function Main () { $p = new pp (); Change ($p); Var_dump ($p); Die;} Function Change (& $p) { $p->ss = 10;} Main ();? >
Object (PP) #1 (1) { ["ss"]=> Int (10)}
Summary: In PHP, an array is a normal variable, and the value is passed as a copy of the argument, regardless of the argument, and the value of the argument can be changed after the reference is passed.
The object of a class is that the value of the argument is changed regardless of whether the value is passed or the reference pass is a reference pass, and is a reference to the object.
Transferred from: http://www.cnblogs.com/zcy_soft/archive/2011/12/10/2283570.html
[Reprint]php Array Class object value passing reference passing differences