PHP Tutorial function usage and definition
Similar to other programming languages, PHP programmers provide a way to define the functionality that it can be called in other places. The syntax for a function is:
Function Definition Method
Function "Function_name" (Arg1, arg2 ...)
{
[Code to execute]
return [Final_result];
}
where [Final_result] usually returns the value of the variable from the function.
Let's take a look at an example
function Double_this_number ($input _number)
{
return $input _number*2;
}
Call method
$x = 10;
$y = Double_this_number ($x);
Print $y;
Output value is
10
Okay, let's take a look at a more complex method of function usage
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 Method
safepost ();
This can not define parameters, because it is $v==0 to set a parameter by default, so it is helpful to extend the function.
This article is original in www.111cn.net reprinted annotated source