This article describes the function invocation and function definition syntax, and explains the functions of theVariable and passing numerical methods to the function. as follows:
First, the basis of the function
PHP provides a number of functions, and allows the user to customize the function, the PHP function definition instance code is as follows:
<?php 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 are defined in the definition of a function, the function can have any number of parameters, the most common method of application is passed by value, or by reference and default parameter values are relatively less. The instance code is as follows:
<?php function MyColor ($inColor = "Blue") { return "My favorite color: $inColor.";} echo MyColor (); Echo MyColor ("Pink");?>
The values that are normally passed are not changed by the internal changes of the function, unless it is a global variable or a reference to the PHP function reference instance, the code is as follows:
<?php function Str_unite (& $string) { $string. = ' also like blue. ';} $str = ' like red, '; Str_unite ($STR); Echo $str; Output: ' Like red, also like blue. '?>
Global variables, the code is as follows:
<?php $a = 1; $b = 2; function Sum () { global $a, $b; $b = $a + $b; } Sum (); echo $b;?>