• PHP Video Tutorials

PHP - func_num_args()



The func_num_args() function can return the number of arguments passed to a function.

Syntax

int func_num_args( void )

The func_num_args() function can return the number of arguments passed into current user-defined function. This function can generate a warning if called from outside of a user-defined function.

Example 1

<?php
   function combined() {
      $num_arg = func_num_args();
      echo "Number of arguments: " .$num_arg . "\n";
   }
   combined('A', 'B', 'C');
?>

Output

Number of arguments: 3	

Example 2

<?php
   function foo() {
      $numargs = func_num_args(); // return the parameters contained in this function
      
      echo "number of argumets:" .$numargs . "\n";
      $arr = func_get_args(); // return an array to $arr
      print_r ($arr); // output all parameters of this array
      echo "\n";
      for($i=0; $i<= $numargs; $i++) {
         echo $arr[$i]. "\n";
      }
   }
   foo(1, 2, 3, 4, 5, 6);
?>

Output

number of argumets:6
Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
    [5] => 6
)

1
2
3
4
5
6
php_function_reference.htm
Advertisements