I. Four elements of a function definition
return type, function name, argument list, function body
1. The simplest way to define
/*function Show ()
{
echo "Hello";
}
Show (); */
2. function definition with parameters
/*function Show ($a)
{
echo $a;
}
Show ("BBBBB"); */
3. function definitions with default values
/*function Show ($a = "C")
{
echo $a;
}
Show (); */
4. There is a return worth function definition
/*function Show ($a, $b)
{
return $a + $b;
}
Echo Show (5,8);
*/
5. Function definitions for variable parameters
/*function Show ()
{
$a = Func_get_args (); Gets the parameters passed in by the user, returns the array
$b = Func_num_args (); Get the number of arguments passed in
$c = 0; Define a variable, store and
for ($i =0; $i < $b; $i + +)
{
$sum = $sum + $a [$i];
}
return $c;
}
Echo Show (1,2,3,4,5,6,7,8,9);
*/
PHP---functions