Home >Backend Development >PHP Tutorial >PHP——Function_Study Notes PHP Function Reference PHP Delay Function PHP Sorting Function
1. Functions and language structures
Language structure: It is the keyword of the PHP language and part of the language grammar; it cannot be defined by the user or added to language extensions or libraries; it may or may not have variables and return value.
Function: It consists of code blocks and can be reused. From the perspective of source code, it is implemented based on the Zend engine. The functions in the ext extension library are implemented in this way.
Language structures are faster than functions
Why language structures are faster than functions? The reason is that in PHP, functions are first decomposed into language structures by the PHP parser (Zend engine), so it can be seen that there are more functions than language structures A layer of parser parsing. In this way, you can better understand which language structures are faster than functions.
Different language structures and functions. The language structure is faster than the function of the corresponding function. The language structure is more reckless in error handling. Since it is a language keyword, it does not have the link of reprocessing. The language structure cannot be disabled in the configuration item (php.ini) , functions can. Language constructs cannot be used as callback functions.
Our common language structures are as follows:
echo(),print(),isset(),empty(),unset(),exit(),die(),if(),for(),while(),switch (),foreach(),array(),list(),include(),require();
2. Custom function
How to define PHP function:
1. Use Start with the keyword 'function'
2. The function name can start with a letter or an underscore: function name()
3. Write the function body within curly brackets
4. The function name is not case-sensitive
e.g:
function aMessage($name){
echo 'hello world by '.$name;
}
$a='xiaoleng';
aMessage($a);
note: PHP syntax execution process
1. Load page
2. Grammar detection (grammar detection-loading function)
3. Execute script
Parameters of function:
PHP functions can have no parameters or several parameters. Multiple parameters are called parameter lists and are separated by commas. The parameters are similar to a variable and are used to pass when calling. data into the function body. By passing parameters, the function can perform operations on the parameters and obtain the results we want.
The return value of the function:
Using the return keyword can make the function return a value, which can return any type including arrays and objects. If return is omitted, the default return value is NULL .
Variableparameters
1) func_num_args() returns the number of parameters
2) func_get_args() returns all parameters
3) func_get_arg() returns one of the parameters, that Parameters to be passed (subscript starts from 0)
The above introduces PHP - Function_Study Notes, including PHP and functions. I hope it will be helpful to friends who are interested in PHP tutorials.