问题
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