If a value is passed, if it is a non-object, a copy of the value will be passed. Any changes to this variable will not affect the original value. Passing a reference or object means passing the real memory address. Changes to this variable will affect the original value.
function f1($a) {//传值 $a = $a + 1; } function f2(&$a) {//传引用 $a = $a + 1; } $b = 1; f1($b); echo $b; // 输出 1 $b = 1; f2($b); echo $b; // 输出 2
Related recommendations:
What is the difference between value assignment and reference assignment in php?
The above is the detailed content of Detailed explanation of the difference between passing by value and passing by reference in PHP. For more information, please follow other related articles on the PHP Chinese website!