This article introduces you to the variable number of parameter lists of PHP functions. Friends in need can refer to
Use the following Function:
func_num_args
Returns the total number of parameters
##func_get_arg Returns a certain number in the parameter list One item
func_get_args Returns an array containing the function argument list
function test() { echo '参数总数;', func_num_args(), "\n"; echo '第一个参数:', func_get_arg(0), "\n"; echo '全部参数;'; print_r(func_get_args()); } test(1, 2, 3, 4); /* 参数总数;4 第一个参数:1 全部参数;Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 ) */
... syntax implementation
function test(...$params) { print_r($params); } test(1, 2, 3, 4); /* Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 ) */
The above is the detailed content of PHP function variable number of parameter lists. For more information, please follow other related articles on the PHP Chinese website!