PHP Function Learning Notes

Source: Internet
Author: User

I. What is a function and why do you use a function
A function is a code that is named to accomplish a particular task. function can save compilation time, no matter how many times it is called
Are compiled only once on the same page, and are easy to maintain, and also improve the readability of the code while maintaining ease of maintenance.

Two. Calling functions

1 $somevalue = function_name ([parameter, ...]);

Three. Defining functions

1 function [&] Function_name ([parameter[, ... ]]) {2list3 }

The statement can be HTML content, or even a function that does not include any PHP statement, and the function name can be a letter or an underscore beginning
Function names are case insensitive.
Four. Variable scope
Variables and parameters defined in the function cannot access external functions, and variables defined outside the function cannot access the contents of the function by default.

If you access a global variable in a function, you can use the Global keyword.

1 Global var1, VAR2, ...

PHP supports declaring that a function variable is static, and usually the first use of a static variable is to assign an initial value.

1 Static var [=value] [,...];

Five. Function parameters

A function can have any number of arguments, and there are two different ways to pass parameters.

The first is more commonly passed by value, and the second is reference passing.


PHP Function Learning Notes

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.