Home  >  Article  >  Backend Development  >  如何获得函数本身有多少个参数

如何获得函数本身有多少个参数

WBOY
WBOYOriginal
2016-06-13 12:02:57955browse

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

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


我想自动获取自定义函数的名称,及其传入多少个参数,怎么获取?
------解决方案--------------------
<br />function hello(){<br />    echo 'function name is:'. __FUNCTION__; // get function itself name<br />    // how to get how many parameters in these function ,<br />    echo '<br>has '.func_num_args().' parameters<br>';<br />    $params = func_get_args();<br />    foreach($params as $param){<br />        echo $param.'<br>';<br />    }<br />}<br />hello(1,2,3);<br />

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