PHP func_num_args() Function

The func_num_args() function is an inbuilt function in PHP that returns the number of arguments in the user-defined function.
Syntax:
func_num_args(): int
Parameters: This function doesn’t accept any parameter.
Return Values: The number of arguments will be returned into the current user-defined function.
Errors: It will generate errors if called from outside of the function.
Example 1: This code demonstrates the func_num_args() function.
PHP
<?php   function sum() {     echo "Arguments in sum function = ", func_num_args(); }   sum(1, 2, 3, 4);   ?> |
Output:
Arguments in sum function = 4
Example 2: The following code demonstrates the func_num_args() function.
PHP
<?php   function foo() {     $numargs = func_num_args();     echo "Number of arguments: $numargs \n";       $arg_list = func_get_args();     for ($i = 0; $i < $numargs; $i++) {         echo "Argument $i is: " . $arg_list[$i] . "\n";     } }   foo(1, 2, 3);   ?> |
Output:
Number of arguments: 3Â Argument 0 is: 1 Argument 1 is: 2 Argument 2 is: 3
Reference: https://www.php.net/manual/en/function.func-num-args.php



