• PHP Video Tutorials

PHP - func_get_args()



The func_get_args() function can return an array comprising a function's argument list.

Syntax

array func_get_args( void )

The func_get_args() function can return an array in which each element is a corresponding member of the current user-defined function's argument list. This function can generate a warning if called from outside of function definition.

Example 1

<?php
   function some_func($a, $b) {
      $param = func_get_args();
      $param = join(", ", $param);
      echo "Received parameters: $param.\n";
   }
   some_func(1, 2, 3, 4, 5, 6, 7, 8);
?>

Output

Received parameters: 1, 2, 3, 4, 5, 6, 7, 8.

Example 2

<?php
   function combined() {
      $num_arg = func_num_args();
      if($num_arg > 0) {
         $arg_list = func_get_args();
         for ($i = 0; $i < $num_arg; $i++) {
            echo "Argument $i is: " . $arg_list[$i] . "\n";
         }
      }
   }
   combined('A', 'B', 'C');
?>

Output

Argument 0 is: A
Argument 1 is: B
Argument 2 is: C
php_function_reference.htm
Advertisements