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

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

WBOY
WBOYOriginal
2016-06-23 13:53:081228browse

<?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();


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


回复讨论(解决方案)

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);

1#正解。。。。

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

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

Statement:
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