开发者

Comma separated values in a string to function arguments

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜