One of the most important tools in any programming language functions are. A function consists of a set of routines and actions throughout the script will be executed many times grouped into a role and from any point of the script can be called and executed. In turn, this feature can receive external parameters of which depends the result of a function.
The functions should always be placed before performing the function call (of course). The syntax of a function is as follows:
function name (parameters) (
instructions on the role
to call the role would be as follows: name (parameters)
An example for understanding the use of functions is as follows:
Create a role to make the sum of two numbers and display the result
add function ($ sumando1, $ sumando2) (
Sum = $ $ $ sumando1 + sumando2
echo $ sumando1 .”+”.$ sumando2 .”=”.$ sum;
An important fact that merits attention is that the variables to declare a function that will only exist or value within the function.
There are cases where we do not know the number of parameters which will proceed to function and in such cases we must use the functions created for this purpose such as:
func_num_args () Number of parameters that have been passed to the function
func_get_args () Returns an element of forming the list of arguments