sammyukavi
sammyukavi

Reputation: 1511

PHP function to calculate number of parameters passed to a function

Is there a PhP function that can count the number of parameters passed to another function? for example

function tobeCounted ("numberOne","numberTwo","numberThree")
{
 //do something with the parameters
}

a function that will count the number of parameters passed to the function above then return three or the indexes of the parameters or parameters themseleves.

Upvotes: 1

Views: 1055

Answers (5)

Matzi
Matzi

Reputation: 13925

You need these:

func_num_args — Returns the number of arguments passed to the function

func_get_args — Returns an array comprising a function's argument list

From here:

http://www.php.net/manual/en/function.func-num-args.php

Upvotes: 2

Vimalnath
Vimalnath

Reputation: 6463

func_num_args()

Use this to get the number of parameters passed

Upvotes: 1

ridecar2
ridecar2

Reputation: 1957

If you use func_num_args() then you get the amount of arguments, rather than func_get_args that gets you the array of arguments.

Upvotes: 3

RyanS
RyanS

Reputation: 4194

Or more directly: func_num_args

Upvotes: 1

user745235
user745235

Reputation:

func_get_args

Upvotes: 2

Related Questions