Saturday, June 13, 2026
HomeLanguagesPHP func_num_args() Function

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

RELATED ARTICLES

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS