PHP function usage method and function definition Method _php Tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.