PHP functions and Transfer Parameters _php tutorial

Source: Internet
Author: User
This tutorial introduces the call to function and the function definition syntax, and then the variables in the function and the passing of numerical methods to the function.

This tutorial introduces the call to function and the function definition syntax, and then the variables in the function and the passing of numerical methods to the function.

First, the basis of the function

The PHP tutorial provides a number of functions and allows the user to customize the function,

PHP function Definition Instance

function MyCount ($inValue 1, $inValue 2)
{
$AddValue = $inValue 1+ $inValue 2;
return $AddValue; Return the result of the calculation
}
$Count = MyCount (59,100);
Echo $Count; Output 159
?>

function One but is defined can be used anywhere.

Second, the function passes the parameter

PHP function parameters in the definition of the function is defined, the function can have any number of parameters, the most common application of the delivery method, is the value of the pass-by. or by reference and default parameter values to apply relatively little.

Instance

function MyColor ($inColor = "Blue")
{
Return "My favorite color: $inColor. N";
}
Echo MyColor ();
echo MyColor ("pink");
?>

The values that are normally passed are not changed by the inside of the function. Unless it's a global variable or a reference to a PHP function Reference instance

Function Str_unite (& $string)
{
$string. = ' also like blue. ';
}
$str = ' like red, ';
Str_unite ($STR);
Echo $str; Output: ' Like red, also like blue. '
?>

Global variables

$a = 1;
$b = 2;
function Sum ()
{
Global $a, $b;
$b = $a + $b;
}
Sum ();
Echo $b;
?>

http://www.bkjia.com/PHPjc/445450.html www.bkjia.com true http://www.bkjia.com/PHPjc/445450.html techarticle This tutorial introduces the call to function and the function definition syntax, and then the variables in the function and the passing of numerical methods to the function. This tutorial is about calling the function and setting the function ...

  • 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.