Functions with a variable number of parameters. Function with the default settings.
A function in PHP can be built-in or user-defined; however, they are both called the same way.
*The general form of a function call is e.g func(arg1,arg2,…)
*The general way of defining a function is
function function_name (arg1, arg2, arg3, …)
{statement list}
To return a value from a function, you need to make a call to return expr inside your function. This stops execution of the function and returns expr as the function’s value.
The following example function accepts one argument, $x, and returns its square:
function square ($x)
{return $x*$x;}
Default parameters like C++ are supported by PHP. Default parameters enable you to specify a default value for function
parameters that aren’t passed to the function during the function call. The default values you specify must be a constant value, such as a scalar, array with scalar values, or constant.
The following is an example for using default parameters:
function increment(&$num, $increment = 1)
{$num += $increment;}
$num = 4;
increment($num);
increment($num, 3);
This code results in $num being incremented to 8. First, it is incremented
by 1 by the first call to increment, where the default increment size of 1 is used, and second, it is incremented by 3, altogether by 4.
Это можно и не писать//Note: When you a call a function with default arguments, after you omit a default function argument, you must emit any following arguments. This also means that following a default argument in the function’s definition, all other arguments must also be declared as default arguments.