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

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

WBOY
Release: 2016-06-13 12:02:57
Original
989 people have browsed it

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

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


我想自动获取自定义函数的名称,及其传入多少个参数,怎么获取?
------解决方案--------------------
<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 />
Copy after login

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