There is a big difference between passing a value in php and passing a reference. a reference can call the memory address to assign a value, in this way, as long as the content in the memory address changes and the variable assigned by the value changes, the value is only used to assign the value of the memory to other variables.
There is a big difference between passing a value in php and passing a reference. a reference can call the memory address to assign a value, in this way, as long as the content in the memory address changes and the variable assigned by the value changes, the value is only used to give the memory value to other variables.
Pass value:
The parameter stack is a copy of the parameter.
Any modification works on the copy. it does not work on the original variable.
Reference:
The stack is a referenced copy. because the reference points to a variable, the reference operation is actually an operation on the variable it points, just reference the grass paper with less understanding of pointers)
The sample code is as follows:
- Function func1 ($ a) {$ a = $ a + 1 ;}
- Function func2 (& $ a) {$ a = $ a + 1 ;}
- $ Sample = 1;
- Func1 ($ sample );
- Echo $ sample; // output 1
- $ Sample = 1;
- Func2 ($ sample );
- Echo $ sample; // output 2
- // The sample code is as follows:
-
- $ Num1 = 15;
- $ Num2 = & $ num1;
- $ Num2 = 20;
- Echo $ num1; // output 20
- ?>
- // The following code is used:
-
- Function func1 ($ ){
- $ A = $ a + 1;
- }
- Function func2 (& $ ){
- $ A = $ a + 1;
- }
- $ Sample = 1;
- Func1 ($ sample );
- Echo $ sample; // output 1
-
- $ Sample = 1;
- Func2 ($ sample );
- Echo $ sample; // output 2
- ?>
Summary:If a value is transferred, if it is not an object, a copy of the value will be carried out. any changes to this variable will not affect the original value. The reference or object will be transferred, which is the real memory address of the fax, the changes made to this variable will affect the original value.