Common php functions: user-defined functions, callback functions, recursive functions, etc.

Source: Internet
Author: User
Common php functions: user-defined functions, callback functions, recursive functions, etc.
Common php functions, examples of php user-defined functions, callback functions, variable functions, and recursive functions, as well as the usage of php global variables, local variables, and static functions.

Php function language structure: if () for () while () switch () echo () print () array () list () foreach () isset () unset () empty () exit () die () include () require ()

Custom functions:

Function fun (){}

1. call function fun ()

";}Echo" ";}jiutb (9," # cccccc "); jiutb (10," red ");?>

Default parameters:

Function jiutb ($ num = 9, $ color = "black "){}

2. variable parameters

3. the sum of infinitely multiple parameters:

4. variable functions

Function fun () {}$ a = "fun"; $ a (2, 3, 4, 5 );

Variable scope: 1. variables outside the global variable function

2. variables in the local variable function

After the glocal keyword is modified, you can change the local variable to a global variable.

Reference parameter: 1. the Function Points internally and externally to the same address.

Callback function: a type of parameter. if a function parameter is the name of another function, this parameter is called a callback function.

Static variables call the same function multiple times. static variables can be tracked continuously.

// When calling a program, count the number of calls of this function. ";}Show (); show () ;?>

Static variable method:

";}Show (); show ();?>

File inclusion: 1. include () contains errors. the script continues to run. 2. require () if an error exists, the script is terminated immediately.

Recursive function: This function is called in the function. 1. sum:

// Recursive function $ num = 100; for ($ I = 1; $ I <= $ num; $ I ++) {$ sum + = $ I ;} echo $ sum;

Function call sequence

Show (); function show () {} show ();

6. php execution sequence 1. loading page 2. syntax check (1. syntax check 2. loading function) 3. execute script

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.