In JavaScript, I can use apply to pass an array as arguments to a function:
var f = function (n,m) {},
args = [1,2];
f.apply(null, args);
I now need to do something similar in PHP i.e. pass an array of items as ‘separate’ arguments to a function.
Is there any way this can be done?
You can use the function
call_user_func_array. Simply pass in your function (as a callback, usually a string with the function name), and an array of arguments.Additional note: for static functions, use
forward_static_call_array.