Open In App

PHP func_get_args() Function

Last Updated : 03 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The func_get_args()  is an inbuilt function in PHP that is used to get a function argument list in an array form. This function is similar to func_get_arg().

Syntax:

array func_get_args()

Parameters: This function does not accept any parameter.

Return Value: This method returns an array, where a copy for each element will be generated for the corresponding member of the current user-defined function’s argument list. 

Example 1: This example illustrates the basic usage of the  func_get_args() function in PHP. 

PHP




<?php
function foo() {
    $arg_list = func_get_args() ;
    var_dump($arg_list);
}
 
foo(1, 2, 3);
?>


Output:

array(3) {
    [0] => int(1)
    [1] => int(2)
    [2] => int(3)
}

Example 2: This is another example that illustrates the basic usage of the func_get_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-get-args.php


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads