func_get_args is an array for getting the parameters in the method. It returns an array and is used with func_num_args;
func_get_arg is the parameter to get the specified offset
func_num_args counts the number of parameters
func_num_args is generally written in a method and is used for counting;
How to use:
[php]
function myargs($a='para1',$b='para2'){
$numargs = func_num_args();
echo "Number of parameters : $numargs
n";
If ($numargs >= 2) {
echo "Second parameters is: " . func_get_arg(1) . "
n";
}
$arg_list = func_get_args();
for ($i = 0; $i < $numargs; $i++) {
echo "parameters $i is: " . $arg_list[$i] . "
n";
}
}
myargs(11, 22);
Will output:
Number of parameters : 2
Second parameters is: 22
parameters 0 is: 11
parameters 1 is: 22
function myargs($a='para1',$b='para2'){
$numargs = func_num_args();
echo "Number of parameters : $numargs
n";
If ($numargs >= 2) {
echo "Second parameters is: " . func_get_arg(1) . "
n";
}
$arg_list = func_get_args();
for ($i = 0; $i < $numargs; $i++) {
echo "parameters $i is: " . $arg_list[$i] . "
n";
}
}
myargs(11, 22);
Will output:
Number of parameters : 2
Second parameters are: 22
parameters 0 is: 11
parameters 1 is: 22