What is the difference between the pass-through and transfer-through of php functions? For such a question, I like to use a program demonstration to obtain the answer. Let's look at a demo record! What is the difference between the pass-through and transfer-through of php functions? For such a question, I like to use a program demonstration to obtain the answer. Let's look at a demo record!
'; Echo' 2) Return Value of the function after passing the value: '. func ($ I ).'
'; Echo' 3) value of the variable $ I after the function is passed: '. $ I .'
'; Echo' 4) value of the variable $ I before function Address Transfer: '. $ I .'
'; Echo' 5) Return Value of the function after the address is passed: '. func (& $ I ).'
'; Echo' 6) value of the variable $ I after the function is transferred: '. $ I .'
'; // Echo func ($ I ).'
';?>
Program output:
1) The variable $ I before the function is passed: 100
2) the return value of the function after passing the value: 200
3) value of the variable $ I after the function is passed: 100
4) value of $ I before function Address Transfer: 100
5) Return Value of the function after the address transfer: 200
6) value of the variable $ I after the function is transferred: 200
Explanation:
1) directly output a variable with a value of $ I = 100.
2) the func function returns an arithmetic addition result $ = 100 + 100
3) The function transfers values. The function is only used within the function, and the variable $ I outside will not be affected.
4) Same as above
5) there is an "&" symbol before the func function parameter, indicating that the address is transferred. Like 2), the return value is the arithmetic running result of the function.
6) func (& $ I), the variable Pointer Points to the position of $ I, which can be understood as an operation on the variable $ I, $ I = $ I + 100; at this time, the variable $ I is equivalent to being assigned a value again.
What will be the result if the 18th line comment of the above Code is removed?
Summary: in order to change the function parameter value while executing the function, the transfer value is not expected to change.