开发者

passing variables for a variable length argument list in php

I wanted to implement my own debug function that has the same signature as sprintf() function which has a variable arg-list:

sprintf('[%s] [%s]', '开发者_JS百科textA','textB');  
sprintf('[%s]', 'textC');

both above will work.

now I want to has a similar debug function that can pass its own arg-list to sprintf():

function debug(A) {
      $msg = sprintf(A);
      ...
}

anyone can tell me how can I pass A to sprintf if A is variable length argument.?

thanks in advance!


function debug() {
      $args = func_get_args();
      $msg = call_user_func_array('sprintf', $args);
}

CodePad.


Have a look at:

  • http://pl.php.net/manual/en/function.func-get-args.php
  • http://pl.php.net/manual/en/function.func-num-args.php

and

  • http://pl.php.net/manual/en/function.call-user-func-array.php
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜