Php function usage and function definition methods. The syntax of a function is: Copy the code of the function definition method: functionfunction_name (arg1, arg2 ...) {[codetoexecute] return [final_result];} The [final_re syntax for a function is:
Function definition method
The code is as follows:
Function "function_name" (arg1, arg2 ...)
{
[Code to execute]
Return [final_result];
}
[Final_result] usually returns the variable value from the function.
Let's look at an example.
The code is as follows:
Function double_this_number ($ input_number)
{
Return $ input_number * 2;
}
Call method
The code is as follows:
$ X = 10;
$ Y = double_this_number ($ x );
Print $ y;
The output value is
10
Okay. let's take a look at a more complex function usage method.
The code is as follows:
Function safePost ($ v = 0)
{
If ($ v = 0)
{
$ Protected = array ("_ GET", "_ POST", "_ SERVER", "_ COOKIE", "_ FILES", "_ ENV", "GLOBALS ");
Foreach ($ protected as $ var ){
If (isset ($ _ REQUEST [$ var]) | isset ($ _ FILES [$ var])
{
Die ("Access denied ");
}
}
}
}
Call method
SafePost ();
This parameter can be left unspecified because a parameter is set for $ v = 0 by default, which is helpful for function extension.
The code for defining the functions of functions is as follows: function "function_name" (arg1, arg2. ..) {[code to execute] return [final_result];} where [final_re...