The difference between PHP value passing and reference passing. When to pass a value when to pass a reference
(1) Passing by value: Any changes to values within the function scope are ignored outside the function
(2) Passing by reference: Any change to a value within a function can also reflect these changes outside the function
(3) Advantages and disadvantages:
A: When passing by value, PHP must copy the value. This can be a costly operation, especially for large strings and objects.
B. Passing by reference does not require copying values, which is good for performance gains.
1 <?Php2Header (' Content-type:text/html;charset=utf-8 ');34//Explore the default delivery mode for array, null, object, resource5Conclusion (1) array By default is a value pass, which can be referenced by adding & passing6(2) Null default is value passing, plus & can refer to pass7(3) A resource is a value pass. You can refer to a pass by adding &8(4) The object is also passed by default, but object value passing is an object identifier9$hero =Array (' No1 ' + ' Batman ', ' no2 ' = ' Superman ');1011$hero 2 = &$hero;12$hero 2[' no1 ' = ' Spider-Man ';13Echo ' <pre> ';14Var_dump ($hero); var_dump ($hero 2); $a = null; $b = &$a; $b = ' abc '; var_dump ($a, $b);
The difference between PHP value passing and reference passing