Im sure there has to be a way to do this:
I want it so that If I call a function like this…
callFunction("var1","var2","var3");
the function ‘callFunction’ will turn these variables into an array i.e:
$array[0] = "var1";
$array[1] = "var2";
$array[2] = "var3";
I want it to generate this array no matter how many variables are listed when calling the function, is this possible?
You can simply do the following:
func_get_argswill return all the parameters passed to a function. You don’t even need to specify them in the function header.func_num_argswill yield the number of arguments passed to the function. I’m not entirely sure why such a thing exists, given that you can simplecount(func_get_args()), but I suppose it exist because it does in C (where it is actually necessary).If you ever again look for this kind of feature in a different language, it is usually referred to as Variadic Function, or “varargs” if you need to Google it quickly 🙂