逗号将字符串中的值分隔为函数参数

function foobar($arg1 , $arg2) { 

    echo $arg1.arg2;

}; 

is there any way to call it like 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.