Home >Backend Development >PHP Problem >How to get all parameters in method in php
php method to obtain all parameters in a method: You can use the func_get_args function to achieve this, such as [$numargs = func_num_args();echo "number of parameters";].
The operating environment of this article: windows10 system, php 7.3, thinkpad t480 computer.
Function introduction:
func_get_args, get all parameters of a function
Specific code:
function foo() { $numargs = func_num_args(); //参数数量 echo "参数个数是: $numargs<br />\n"; if ($numargs >= 2) { echo "第二个参数的值:" . func_get_arg(1) . "<br />\n"; } $arg_list = func_get_args(); for ($i = 0; $i < $numargs; $i++) { echo "第{$i}个参数值:{$arg_list[$i]}<br />\n"; } } foo(1, 'd', 3,4);
Output:
参数个数是: 4 第二个参数的值:d 第0个参数值:1 第1个参数值:d 第2个参数值:3 第3个参数值:4
Related recommendations :php tutorial
The above is the detailed content of How to get all parameters in method in php. For more information, please follow other related articles on the PHP Chinese website!