Home > Article > Backend Development > What does function mean in php
What does function mean in php?
function is a keyword used to declare user-defined functions.
The syntax structure of PHP declaration function
Function function_name($argument1,$argument2,$argument3,......$argumentn) { //函数代码code Return 返回值; }
Among them:
function_name: The name of the function to be created. This name will be used when it is called later. The function name should be unique, Because PHP does not support overloading. When naming functions, you need to follow the same principles as variable naming
. However, the function name cannot start with $, but the variable can.
argument: to be passed The value given to the function. The function can have multiple parameters, with commas between them. But the parameter items are optional and you can not pass any parameters when calling the function.
code: is when the function is called A piece of code that is executed when. If there are two or more statements, the code must be enclosed in curly braces "{}". However, if there is only one code, curly braces are not required.
Return: Returns the value required by the calling code. Any type can be returned, including lists and objects. This causes the function to immediately end its execution and pass control back to the line on which it was called.
Examples include:
function jia($a) { $b = $a+10; return $b; }
The above is a custom function, let’s see how to use it
echo jia('10');
The displayed result is 20
Here jia is the custom function name, so just give $ The result returned by any number is 10. This is a customized function. This example is very simple~ But by customizing the function, you will find that everything becomes better.
Recommended: "PHP Tutorial"
The above is the detailed content of What does function mean in php. For more information, please follow other related articles on the PHP Chinese website!