开发者

Comma separated values in a string to function arguments

开发者 https://www.devze.com 2023-02-08 18:23 出处:网络
function foobar($arg1 , $arg2) { echo $arg1.arg2; }; is there any way to call it lik开发者_运维百科e this:
function foobar($arg1 , $arg2) { 

    echo $arg1.arg2;

}; 

is there any way to call it lik开发者_运维百科e this:

$args =  'foo, bar';
foobar($args);

I know I can do this with a array, but my foobar() already have a lot of code calling it with 2 arguments.

Thank you,

mjs


You have to use call_user_func_array for this. Like so:

call_user_func_array('foobar', explode(',', $args));

This would be the same as doing:

foobar('foo', 'bar');


call_user_func_array('foobar', explode(', ', 'foo, bar')); should do the trick.

0

精彩评论

暂无评论...
验证码 换一张
取 消