Home > Article > Backend Development > How to call php custom function
Whether it is a custom function or a system function, if these functions are not called, it will not be executed. In general, you just need to use the function name and parameter list to call the function where you need to use it. After the function is called, it starts executing the code in the function body. After the execution is completed, it returns to the calling location and continues execution below. Therefore, the name of the function when calling the function can be summarized as the following three functions.
(1) Call the function through the function name, let the code of the function body run, and call the function several times body, the code will be executed several times.
(2) If the function has a parameter list, you can also pass the corresponding value to the parameter through the parentheses after the function name, and use the parameters in the function body to change the internal code of the function. Execution behavior.
(3) If the function has a return value, after the function is executed, the value after return will be returned to the location where the function was called, so that the function name can be regarded as the function's Use the returned value.
## As long as the declared function is visible in the script, it can be called anywhere in the script through the function name. In PHP, you can call a function after it is declared, you can call it before the function is declared, and you can also call a function within a function. Sometimes, although a function is declared, if it is not called, the function will not be executed. If we call it once before and once after the function declaration, the function will be executed twice.
How to declare a php custom function we introduced how to create a function custom function. After the function is defined, all that needs to be done is to call the function. The operation is It's relatively simple, just quote the function name and assign the correct parameters.
Calling php custom function instanceThe following defines a function test() to calculate the square of the incoming parameters, and then together with the expression All formulas and results are output, and the code is displayed as follows:
<?php
function test($num)
{
return "$num * $num = ". $num * $num;
}
echo test(10);
?>
10 * 10 = 100
Two parameters of php custom function.
The above is the detailed content of How to call php custom function. For more information, please follow other related articles on the PHP Chinese website!