func_get_arg() and func_get_args() functions in PHP

By: Marlin Viewed: 192 times  Printer Friendly Format    


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.



Most Viewed Articles (in PHP )

Latest Articles (in PHP)

Comment on this tutorial