PHP func_num_args() Function
The PHP func_num_args() function returns the number of arguments passed to the function.
This function may be used in conjunction with func_get_arg() and func_get_args() to allow user-defined functions to accept variable-length argument lists.
Syntax
func_num_args()
Parameters
No parameter is required.
Return Value
Returns the number of arguments passed into the current user-defined function.
Exceptions
Generates a warning if called from outside of a user-defined function.
Example: func_num_args() example
The example below shows the usage of func_num_args() function.
<?php function myFunction() { //getting the number of arguments passed $numargs = func_num_args(); echo "Number of arguments: $numargs\n"; //displaying the second argument if ($numargs >= 2) { echo "Second argument is: ".func_get_arg(1)."\n"; } //displaying the array containing //function's argument list print_r(func_get_args()); } myFunction(10, 20, 30); ?>
The output of the above code will be:
Number of arguments: 3 Second argument is: 20 Array ( [0] => 10 [1] => 20 [2] => 30 )
❮ PHP Function Handling Reference