The PHP function array_map(...)
expects a callback as first parameter (or null
for creating an array of arrays) and a variable number of array arguments, e.g.:
$foo => array_map(null, $bar, $buz);
Now I have a case, where I need to pass to array_map(...)
a variable number of arrays. I cannot hard-code this, since the arrays for the array_map(...)
's input are generated dynamically.
function performSomeLogicAndGetArgumentsForMyFunction() {
...
return ['bar' => [...], 'buz' => [...]];
}
$foo = array_map(null, performSomeLogicAndGetArgumentsForMyFunction());
It doesn't work this way, since array_map(...)
expects a variable number of array and not an array of arrays.
Is there a solution for this? How can I keep the call flexible and pass a variable number of arguments to the array_map(...)
? (It also applies to every other variadic function I cannot manipulate.)