PHP Common functions: Custom functions, callback functions, recursive functions, etc.

Source: Internet
Author: User
What are common PHP functions, some examples of PHP custom functions, callback functions, variable functions and recursive functions, and the use of PHP global variables and local variables, static functions, and so on.

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 (Ten, "Red");? >

Default parameters:

function Jiutb ($num =9, $color = "Black") {}

2. Variable parameters

3, the sum of the infinite number of parameters:

4. Variable function

function Fun () {} $a = ' fun '; $a (2,3,4,5);

Variable scope: 1. Variables outside the global variables function

2. Variables inside a local variable function

glocal keyword modification to change local variables to global variables

Reference parameter: 1, inside and outside the function point to the same address

callback function: is one of the parameters. The parameter of a function is the name of another function, so this parameter is called the callback function

Static variables call the same function multiple times, and static variables can be tracked down.

This function was called several times when the program was called. ";} Show (); show ();? >

Static Variable method:

";} Show (); Show (); Show (); >

File contains: 1.include () contains error, script continues to execute 2.require () the script terminates immediately if it contains an error

Recursive function: Function inside call this function 1. Sum:

Recursive function $num=100;for ($i =1; $i <= $num; $i + +) {$sum + = $i;} Echo $sum;

The order in which functions are called

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

6.php execution order 1, Load page 2, syntax detection (1. Syntax detection 2. Load 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.