php8.5
Home/ Manual/ funchand / functions/ func_num_args

func_num_args

PHP function Edit on GitHub ✎

(PHP 4, PHP 5, PHP 7, PHP 8)

Returns the number of arguments passed to the function

Description

func_num_args(): int

Gets 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.

Parameters Parameters

Return Values

Returns the number of arguments passed into the current user-defined function.

Errors/Exceptions

Generates a warning if called from outside of a user-defined function.

Examples

func_num_args() example

php
<?php
function foo()
{
    echo "Number of arguments: ", func_num_args(), PHP_EOL;
}

foo(1, 2, 3);   
?>

The above example will output:

output
Number of arguments: 3

Notes Func-named-params

See Also

Source: reference/funchand/functions/func-num-args.xml · from the official PHP manual (php/doc-en)