Php function value transfer and address transfer-PHP development

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.