Monday, December 22, 2025
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
32456 POSTS0 COMMENTS
Milvus
111 POSTS0 COMMENTS
Nango Kala
6823 POSTS0 COMMENTS
Nicole Veronica
11958 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12038 POSTS0 COMMENTS
Shaida Kate Naidoo
6958 POSTS0 COMMENTS
Ted Musemwa
7203 POSTS0 COMMENTS
Thapelo Manthata
6911 POSTS0 COMMENTS
Umr Jansen
6890 POSTS0 COMMENTS