开发者

How to call a function with a variable number of parameters which correspond to an array values?

OK, I know it sounds weird but I need to make a function that will receive two parameters the first one is a string and the second an array (containing strings).

This function will then call sprintf. My first parameter will be $format and my array will correspond to the various $args.

开发者_如何转开发

How can I achieve this (if possible)?

Thanks!


Well you want the vsprintf() function.


Like Orbling answered, for this particular case you need vsprintf.

But, in a generic case, to call a function with variable number of parameters, you can use func_get_args() inside the function which you desire to accept multiple (any number of variable arguments). This function (when called inside your function) returns an array containing all the parameters passed while calling your function.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜