illustrate
1. In passing by value, PHP must copy the value. Especially for large strings and objects, this will be an expensive operation.
2. Passing by reference does not require copying the value, which is beneficial to performance improvement.
Example
pass by value
$a = "test"; $b = $a; $a = "newtest"; echo $a; //output newtest echo $b; //Output test --or $a = "test"; $b = $a; $b = "newtest"; echo $a; //Output test echo $b; //output newtest
pass by reference
$a = 'test'; $b = &$a; //Reference assignment, $a and $b point to the same space, and they are relative to a community $b = 'newtest'; //If $b changes, $a will change accordingly echo $a; // output newtest echo $b; //output newtest
The above is a comparison of PHP pass by value and pass by reference. I hope it will be helpful to everyone.