php--function _ Learning note PHP Function reference PHP delay function php sort letter

Source: Internet
Author: User
I. Function and language structure

Language structure: is the PHP language keywords, language grammar part; it can not be defined by the user or added to the language extension or library; it can have or can have no variables and return values.

Functions: There are blocks of code that can be reused. From the source point of view, that is, based on the Zend engine base to achieve, Ext extension Library functions are implemented in this way.

Language structure is faster than function
The reason why the language structure is faster than the function is in PHP, the function must first be decomposed into the language structure by the PHP parser (Zend Engine), so there is this visible, the function is more than the language structure of a layer of parser parsing. This can be better understood, what language structure is faster than the function.
Language structure and function of the different language structure than the corresponding function of the function of the fast language structure is more reckless in error handling, because it is a language keyword, so there is no re-processing link language structure can not be disabled in the configuration item (php.ini), function is possible. The language structure cannot be used as a callback function.
Our common language structure is as follows:
Echo (), print (), isset (), Empty (), unset (), exit (), die (), if (), for (), while (), switch (), foreach (), array (), list (), Include (), require ();

Two. Custom functions

How PHP functions are defined:

1. Start with the keyword ' function '

2. The function name can start with a letter or an underscore: functions name ()

3. Write the function body inside the curly braces

4. Function names are case insensitive

e.g:

function Amessage ($name) {
echo ' Hello World by '. $name;
}
$a = ' Xiaoleng ';
Amessage ($a);

note:php Syntax Execution process

1. Loading the page

2. Syntax detection (syntax detection-load function)

3. Execute the Script

Parameters of the function:

PHP functions can have no parameters, there can be several parameters, multiple parameters are called parameter lists, separated by commas, the parameters are similar to a variable, called to pass data into the function body. By passing parameters, we can make the function implement the operation of the parameters and get the result we want.

The return value of the function:

Use the return keyword to return a value to a function that returns any type that includes an array and an object, or NULL if the return is omitted.

variable Parameters

1) Func_num_args () returns the number of parameters
2) Func_get_args () return all parameters
3) Func_get_arg () returns one of the parameters, the one to be passed (the subscript is starting from 0)

The above describes the php--function _ learning notes, including PHP, function aspects of the content, I hope the PHP tutorial interested in a friend helpful.

  • 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.