How to get all parameters in method in php

王林
Release: 2023-03-08 07:18:02
Original
4643 people have browsed it

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";].

How to get all parameters in method in php

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
\n"; if ($numargs >= 2) { echo "第二个参数的值:" . func_get_arg(1) . "
\n"; } $arg_list = func_get_args(); for ($i = 0; $i < $numargs; $i++) { echo "第{$i}个参数值:{$arg_list[$i]}
\n"; } } foo(1, 'd', 3,4);
Copy after login

Output:

参数个数是: 4
第二个参数的值:d
第0个参数值:1
第1个参数值:d
第2个参数值:3
第3个参数值:4
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!