Home > Backend Development > PHP Tutorial > PHP func_num_args() function introduction and usage examples

PHP func_num_args() function introduction and usage examples

巴扎黑
Release: 2023-03-07 20:56:02
Original
9293 people have browsed it

func_num_args(): Returns the number of parameters passed in to the calling function, the type is integer.

This function can be used in conjunction with func_get_arg() and func_get_args() to allow user-defined functions to receive variable-length parameter lists.

Return value

Returns the number of parameters passed into the function defined by the current user.

Usage example:

function foo()
{
   $numargs = func_num_args();//返回这个函数所含的参数
   echo "Num fo argumets : $numargs <br>\n";
   $arr=func_get_args();//返回一个数组给$arr
   print_r($arr);//输出这个数组所有的参数
   echo "<hr>";
   for($i=0;$i<=$numargs;$i++)
   {
       echo $arr[$i]."<br>";
   }
}
foo(1,2,3,45,6);
Copy after login

The running results are as follows:

Num fo argumets : 5
Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 45 [4] => 6 )
--------------------------------------------------------------------------------
1
2
3
45
6
Copy after login

Example 2:

<?php
function foo() {
    include &#39;./fna.php&#39;;
}
foo(&#39;First arg&#39;, &#39;Second arg&#39;);
?>
fna.php
<?php
$num_args = func_num_args();
var_export($num_args);
?>
Copy after login

The above is the detailed content of PHP func_num_args() function introduction and usage examples. 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 admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template