Programming Tutorials

func_get_arg() and func_get_args() functions in PHP

By: Marlin in PHP Tutorials on 2011-10-28  

You may pass any number of extra parameters to a function, regardless of the prototyping. In addition, the arguments passed to a function will be available via the variable names defined in the function prototype, as well as via the func_get_arg() and func_get_args() functions.

For example:

function printme ($arg) {
for ($ndx = 0; $ndx < $num_args; ++$ndx)
$output .= func_get_arg ($ndx);
print $output;
printme ("one ", "two"); # This prints "one two"

This behavior is useful for setting default values for function arguments and for ensuring that a certain number of arguments get passed to a function.

Add Comment

* Required information


No comments yet. Be the first!

Most Viewed Articles (in PHP )

Latest Articles (in PHP)