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 execute Javascript through PHP by calling javascript code/function as a string in PHP and send it to the client browser to execute.
PHP Parameterized functions are the functions with parameters. You can pass any number of parameters inside a function. These passed parameters act as variables inside your function. They are specified inside the parentheses, after the function name.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With