php - dynamic amount of variables passing to function
function, php, variables
Solution
I would rather use an array as a parameter and inside the function check it to see if your variable exists:
function abc ($data) {
if(isset($data['x']){
//whatever
}
if(isset($data['y']){
//whatever
}
...
}
Problem
I am looking for the most elegant way to pass variable number of arguments to pass a function. Consider such a function: ``` function abc ($x, $y, $l, $m) { ... } ``` Is there an elegant way without lots of "ifs" or array of variables pasing as one variable to call a function with: ``` all ($x, $y, $l, $m) arguments first three ($x, $y, $l) arguments first and third ($x, $l) arguments only second ($y) argument last two ($l, $m) arguments ``` Please advice.