简体   繁体   中英

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]', '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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM