|
One of the most important hardware in any computer language there are the functions. A function consists of a set of routines and actions that along the script multitude of times is going to be executed grouped in a FUNCTION and from any point of the script it can be called and executed. In turn, this function can receive external parameters on which the result of a function depends.
The functions must always be placed before realizing the call to the function (as it is logical). The syntax of a function is the following one:
function name (parameters) {
instructions of the function
}
to call to the function it would perform the following form: name (parameters)
An example to understand the use of functions is the following one:
We will create a function that realizes the sum of two numbers and shows the result
function to add up ($sumando1,$sumando2) {
$ suma=$sumando1+$sumando2
I begin $sumando1." + ". $sumando2." = ". $suma;
}
to add (5,6)
An excellent fact that it is necessary to emphasize is that the variables that we declare inside the function alone will exist or have the above mentioned value inside the function.
There exist cases in which we do not know the number of parameters that we will spend to him to the function and in these cases we must use the functions created to the effect as they are:
func_num_args () I Number of parameters that have passed to the function
func_get_args () He Returns an element of those who form the list of arguments
|