Home > Backend Development > PHP Tutorial > 怎么获得函数本身有多少个参数?

怎么获得函数本身有多少个参数?

WBOY
Release: 2016-06-23 13:53:08
Original
1276 people have browsed it

<?php function hello($param1,$param2,...){	echo 'function name is:'. __FUNCTION__; // get function itself name	// how to get how many parameters in these function ,	echo '<br>has ? parameters';}hello();
Copy after login


我想自动获取自定义函数的名称,及其传入多少个参数,怎么获取?


回复讨论(解决方案)

function hello(){    echo 'function name is:'. __FUNCTION__; // get function itself name    // how to get how many parameters in these function ,    echo '<br>has '.func_num_args().' parameters<br>';    $params = func_get_args();    foreach($params as $param){        echo $param.'<br>';    }}hello(1,2,3);
Copy after login

1#正解。。。。

func_num_args() 返回实际传入的参数个数
func_get_args() 返回实际传入的参数值数组

注意实际参数与定义参数的区别

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 admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template