The function is a piece of code that can be called using the name. We have already been given several functions provided by PHP, such as array (), each (), list (), explode () and implode (). Features recognized by the parentheses occurring after their name. In these brackets (if required) is given parameters for the function. Some functions

return a value, and so calling this function, you can insert as any other expression to the list of parameters of another function or eg. to calculate.
The developer can also create your own functions.


function sum ($parameter1 = 0, $parameter2 = 0)

$value = $parameter1 + parameter2;

return $value;



It defines a function named amount. It is used to calculate the sum of the two expressions given as parameters (the following parameters separated by a comma). If you miss any of the parameters assigned to it will be set to 0 – this is due to select  ” = 0″ after specifying the parameter name in the function definition (not necessary). With parameter functions can be used like any other variable, but of course only within that function. Inside the function is available only variables in it and defined parameters.

You can also get to the other variables. To determine what is returned by the function is the „return” statement. It can be called anywhere in the function – after coming to this instruction ends the execution of the function.

The function can not return any value. This function is useful if you often repeated is a piece of code. This function finishes its execution when it reaches the end of its definition or return (this time being called without a parameter, as the function does not return any value).
Functions in PHP can not be re-defined. They can be defined basically anywhere in the code. Inside the function can be arbitrary, correct in terms of syntax code – even definitions of other functions or classes.

Cookies help us deliver our services. By using our services, you agree to our use of cookies. More Info | Close