The syntax for a function is:
Function Definition Method
Copy CodeThe code is as follows:
Function "Function_name" (Arg1, arg2 ...)
{
[Code to execute]
return [Final_result];
}
where [Final_result] usually returns the value of a variable from a function.
Let's look at an example
Copy CodeThe code is as follows:
function Double_this_number ($input _number)
{
return $input _number*2;
}
Calling methods
Copy CodeThe code is as follows:
$x = 10;
$y = Double_this_number ($x);
Print $y;
The output value is
10
Well, let's look at a more complicated way of using the function
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");
}
}
}
}
Calling methods
Safepost ();
This can not define the parameters, because to the $v==0 default set a parameter, so that the extension of the function is very helpful.
http://www.bkjia.com/PHPjc/321825.html www.bkjia.com true http://www.bkjia.com/PHPjc/321825.html techarticle The syntax for a function is: The function definition method copies the code code as follows: Functions "function_name" (Arg1, arg2 ...) {[code to execute] return [Final_result];} where [Final_re ...