Paul Konstanski
asked on
Convert elements of array into arguments to be passed into a PHP function.
I have a situation where I need to pass a variable number of arguments into a function that I don't have control over.
The function has this format: setFunction ($type, $var1, [$var2], [$var3]...) where $type is a setting ('left", "right", "center"). There must be at least 1 variable, but you can have as many as you want.
This normally is set at the time of calling the function by setting the variables like this.
Thanks.
The function has this format: setFunction ($type, $var1, [$var2], [$var3]...) where $type is a setting ('left", "right", "center"). There must be at least 1 variable, but you can have as many as you want.
This normally is set at the time of calling the function by setting the variables like this.
$type = "left";
$var1 = "10";
$var2 = "abcdef";
$var3 = "255";
$display = setFunction($type, $var1, $var2, $var3);
What I'm wanting to do is be able to create the additional arguments on the fly from an array. So in the above example it would be like this:$type = "left";
$myvars = array("10", "abcdef", "255");
// here is where I want some magic to happen that would create the variables that would then be appended to the function call.
// so you simply build the array and it creates the $var1, $var2, $var3 or how ever many variables you have based on the number of elements in the array.
$display = setFunction($type, magic variable variables here);
I'm trying to create a shortcut so I can call a function to build my setFunction call from an array rather than have to always declare and build it each time.Thanks.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER