Home >Backend Development >PHP Tutorial >Usage of func_get_args function in PHP function parameters
This article mainly introduces the usage of functions with variable number of parameters defined in PHP. It analyzes the usage skills of func_get_args with examples. It has certain reference value. Friends in need can refer to it.
The examples in this article describe PHP Define function usage with a variable number of parameters. The specific analysis is as follows:
The function parameters in php do not need to be fixed, and there is no need to even define parameters. Use the func_get_args() function inside the function to obtain the parameter list. You can specify any parameters for the function when calling, which is very convenient
<?php function addanything (){ $total = 0; $args = func_get_args (); for ($i = 0; $i < count ($args); $i++){ if (is_int ($args[$i])){ $total += $args[$i]; } } return $total; } echo addanything (1,5,7,8,11) . "<br />"; ?>
Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
How to generate a reference implementation tree in PHP
Three commonly used methods in the PHP SPL standard library Large function
A brief description of the adapter pattern in PHP design patterns
##
The above is the detailed content of Usage of func_get_args function in PHP function parameters. For more information, please follow other related articles on the PHP Chinese website!