Home >Backend Development >PHP Tutorial >PHP reference calls
1.function test($arr){}
echo test(&$arr);
2.function test(&$arr){}
echo test($arr);
1 and 2 have the same effect.
3.function &test($arr){return $result;}
echo &test($a); is valid
echo test($a); returns a value, not a reference
Summary: only add before the method name when defining a method & When calling a method, a reference is returned only when & is added before the method name.
4.$a=$b;
When neither $a nor $b is reassigned, that is, when no writing operation occurs, the same as $a =&$b is the same, which is equivalent to assigning a reference.
Only when $a or $b changes, a copy of the value will be assigned to $a