How to pass a string with a few comma separated values as function parameters

时光怂恿深爱的人放手 提交于 2019-12-24 09:30:59

问题


For instance:

$str = '1, 2, 4, 13';

I'd like the effect to be as if it were:

func(1, 2, 4, 13)

回答1:


$params = explode(', ', $str);
call_user_func_array("func", $params);



回答2:


$str = '1, 2, 4, 13';
function func($one, $two, $three, $four) {
    var_dump(func_get_args());
}
call_user_func_array('func', explode(', ', $str));

Remember, you can pass as many parameters to a function and accessing them with func_get_args(), they dont have to be defined in the methods signature.



来源:https://stackoverflow.com/questions/5669717/how-to-pass-a-string-with-a-few-comma-separated-values-as-function-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!