The syntax for a function is:
Function Definition Method
CopyCode 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.Copy codeThe Code is as follows: function double_this_number ($ input_number)
{
Return $ input_number * 2;
}
Call MethodCopy codeThe 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.Copy codeThe 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.