This tutorial is about calling functions and function definition syntax, and talking about variables in functions and passing numeric methods to functions.
The basis of a function
The PHP tutorial provides a number of functions and allows the user to customize the function,
PHP function Definition Instance
<?php
function Mycount ($inValue 1, $inValue 2)
{
$AddValue = $inValue 1+ $inValue 2;
return $AddValue; Return calculation results
}
$Count = Mycount (59,100);
Echo $Count; Output 159
The?> function can be used anywhere but defined.
Second, the function passes the parameter
PHP function parameters in the definition of the definition, the function can have any number of parameters, the most common method of transmission, is delivered by value. or by reference and default parameter values are relatively few.
Instance
<?php
function MyColor ($inColor = "Blue")
{
Return "My favorite color: $inColor. N";
}
Echo MyColor ();
echo MyColor ("pink");
?> generally passed values are not changed by internal changes in functions. Unless it's a global variable or reference. php Function Reference Instance
<?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
<?php
$a = 1;
$b = 2;
function Sum ()
{
Global $a, $b;
$b = $a + $b;
}
Sum ();
Echo $b;
?>