Declare and apply various forms of PHP functions (Recommended learning: PHP video tutorial)
Whether we are using a system function or a custom function, we must understand a function through the following three elements of the function:
function description, function The parameters and the return value of the function.
Function of regular parameters
Function format description of regular parameters:
string example(string name,int age,double height)
The so-called function of regular parameters is the sum of actual parameters and The formal parameters should be equal in number and consistent in type. Just like strongly typed languages like C or Java.
The above function has three parameters. The number and order of parameters passed when calling must be consistent.
string chr(int $ascii) //返回指定的字符 float ceil(float $value) //进一法取整 array array_combine(array $keys,array $values)//合并一个数组 string implode(string $glue,array $pieces)
Function of pseudo-type parameters
Function format description of pseudo-type parameters:
mixed funName(mixed $a, number $b, callback $c)
PHP is a weakly typed language, not only when declaring variables There is no need to specify a type, and of course there is no need to specify a type when declaring a function, so in PHP, any type of value can be passed to each parameter of the function.
Three pseudo-types: mixed, number and callback.
bool empty(mixed $var) //检查一个变量是否为空 bool usort(array &$array,callback $cmp_function) //使用用户自定义的比较函数对数组中的值进行排序 number abs(mixed $number) //绝对值
For more PHP related technical articles, please visit the PHP Graphic Tutorial column to learn!
The above is the detailed content of Three elements of php function. For more information, please follow other related articles on the PHP Chinese website!