I am trying to use a list of variables as arguments when DEFINING a function. It seems like it should be straight forward, but no. The callback is easy and I am able to use (...$listOfVariables) to get all needed arguments into callback, but it does not work when defining the function.
I need this because I have 50 different functions that require the use all of the same arguments. When the list of arguments changes (which it does) I need a central location to make sure all of the different functions use the new list of arguments. (Again, I already can do this with the callback, but not when I define the function)
Here is how I would normally do it for a few arguments.
$var1 = 'var1text';
$var2 = 'var2text';
$var3 = 'var3text';
function funcname($var1, $var2, $var3){
echo $var1;
}
That works fine, but my list of variables changes a lot and is used in many other functions. I may be going about it the wrong way and I'm open to whatever suggestions you have. Below is what I need to accomplish.
EDITED
1.variables that are defined outside of the function
$var1 = 'var1text';
$var2 = 'var2text';
$var3 = 'var3text';
2.a variable that contains all of those variables
$listOfVar = $var1, $var2, $var3; //***see note below***.
3.include list of variables that I can use within the function so I don't have to list them one at a time like I did in the first snippet.
function funcname($listOfVar){
echo $var1;
}
the full code I am trying to make work:
$var1 = 'var1text';
$var2 = 'var2text';
$var3 = 'var3text';
$listOfVar = $var1, $var2, $var3;
function funcname($listOfVar){
echo $var1;
}
**I realize the commas in the $listOfVar syntax is not correct for this, but what IS the syntax then? I've tried variable variables ($$) - trying to convert a string to variable name references. I have tried arrays. I have tried literally hundreds of variations of these and I am just out of ideas for this. Please help.