HomeLanguagesPHP func_get_args() Function

PHP func_get_args() Function

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

RELATED ARTICLES

Most Popular

Dominic
32688 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7057 POSTS0 COMMENTS
Nicole Veronica
12198 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12293 POSTS0 COMMENTS
Shaida Kate Naidoo
7182 POSTS0 COMMENTS
Ted Musemwa
7447 POSTS0 COMMENTS
Thapelo Manthata
7160 POSTS0 COMMENTS
Umr Jansen
7150 POSTS0 COMMENTS