Arun
Arun

Reputation: 3721

how could make a function which accept dynamic number of arguments?

My doubt is, how could I make a function which can accept dynamic number of arguments? For example

in the case of setcookie()

setcookie("TestCookie",$value);

is accepting only two values and set the cookie. And the same function

setcookie("TestCookie",$value, time()+3600*24);

which accept 3 parameters. And

setcookie("TestCookie", $value, time()+3600*24, '/', NULL, 0);

will also work.

How could I make it possible in my own functions?

Upvotes: 0

Views: 41

Answers (1)

Rakesh Sharma
Rakesh Sharma

Reputation: 13728

pass an array to function for this like

$arr = array(1,2,3,3,4); //pass any number of values

function myfunction($arr) {
}

Or you define more variable to null at function initialize like

function myfunction($param1= '', $param2='', $param3='') //set null to default

calling:-

myfunction('',2);

Upvotes: 1

Related Questions