DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Variable-length Argument List In PHP

03.18.2006
| 18549 views |
  • submit to reddit
        See the document for 
<a href=http://php.net/manual/en/function.func-num-args.php>func_num_args()</a>, <a href=http://php.net/manual/en/function.func-get-arg.php>func_get_arg()</a>, and <a href=http://php.net/manual/en/function.func-get-args.php>func_get_args()</a>.
function foo()
{
   $numargs = func_num_args();
   echo "Number of arguments: $numargs<br />\n";
   if ($numargs >= 2) {
       echo "Second argument is: " . func_get_arg(1) . "<br />\n";
   }
   $arg_list = func_get_args();
   for ($i = 0; $i < $numargs; $i++) {
       echo "Argument $i is: " . $arg_list[$i] . "<br />\n";
   }
}

foo(1, 2, 3);