Php summary 6.0 -- custom function, reference value passing, php6.0

Source: Internet
Author: User

Php summary 6.0 -- custom function, reference value passing, php6.0

6.1 User-Defined Functions

Function Name (parameter [= default value], parameter [= default value]...) {

Function body

[Return val];

}

1) No parameter is returned

2) if a parameter exists, no response is returned.

3) if any parameter is returned

The code in the function is not executed immediately and will be executed only when called.

Call: function name ([parameter list])

Question: What are the differences between the following two functions?

Function demo {

Echo 1111;

} // 1111 is printed on the page and cannot be assigned to a variable.

 

Function demo {

Return 1111;

} // It is not printed on the page, but can be assigned to a variable.

4) recursive functions

Recursive functions must be terminated.

It is often used in php to recursively Delete directory files.

6.2 reference and pass value of a Variable

Reference Value: php allows multiple variables to point to the same memory space.

The reference transmits the content.

Question: What are the output of the following two programs?

<? Php $ a = 3; $ B = $ a; $ a = 4; echo $ B; // 3?> <? Php $ a = 3; $ B = & $ a; $ a = 4; echo $ B; // 4?>

 

 

 

 

 

 

 

 

 

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.