I know it is possible to pass a single function name with its parameter(s) as a parameter using call_user_func() or [URL=“http://us.php.net/manual/en/function.call-user-func-array.php”]call_user_func_array() for a function with an array of parameters. But is there any way to pass an array of function names with their parameters to a function?
Let’s say I have 4 functions like this:
func1($param1, $param2);
func2();
func3($param3);
func4($param4, $param5, $param6);
I would like to pass all the function names with their parameters to a single function. But I cannot figure out how to do it, or if it is even possible.
I tried passing a complex array to the called function similar to this (I don’t remember exactly how I tried it):
$func_array[0][‘func’] = ‘func1’;
$func_array[0][‘param’][0] = $var1;
$func_array[0][‘param’][1] = $var2;
$func_array[1][‘func’] = ‘func2’;
$func_array[2][‘func’] = ‘func3’;
$func_array[2][‘param’][0] = $var3;
$func_array[3][‘func’] = ‘func4’;
$func_array[3][‘param’][0] = $var4;
$func_array[3][‘param’][1] = $var5;
$func_array[3][‘param’][2] = $var6;
Processing the array in the called function with foreach was a pain and I could not get it to work right. Unwinding the array with foreach, I could test the key to see if it equals ‘func’, but I couldn’t figure out what to do with the $func_array[0][‘param’] array. I couldn’t find a function to “explode” an array, either.
Anyone have any ideas or know of a better way? There has to be a way this can be done.