How to use function with different number of arguments in PHP

1 Answer

0 votes
function AFunction() 
{
    for ($i = 0; $i < func_num_args(); $i++) 
    {
        printf("Argument %d = %s ", $i, func_get_arg($i));
    }
    echo "<br />";
}

AFunction(1, 3);
AFunction("php");
AFunction(1, 3.14, "php");

   
/*
run:
    
Argument 0 = 1 Argument 1 = 3 
Argument 0 = php 
Argument 0 = 1 Argument 1 = 3.14 Argument 2 = php 

*/

 



answered Nov 20, 2017 by avibootz

Related questions

3 answers 187 views
1 answer 230 views
1 answer 151 views
1 answer 192 views
...