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