function debug() { if (!defined('DEBUG')) { return; } $args = func_get_args(); $msg = $args[0]; array_shift($args); $extra = implode(' ', $args); printf("[debug] $msg [extra] $extran"); } function debugn($times) { static $n = 0; if ($n < $times) { $n++; $args = func_get_args(); array_shift($args); $call = 'debug('; foreach($args as $arg) { if (gettype($arg) == 'string') $arg = ""$arg""; $call .= $arg.','; } $call = substr($call, 0, -1).');'; eval($call); } return; } |
define('DEBUG', true); for($i = 0; $i < 100; $i++) { debugn(7, 'the i value currently is '.$i); if ($i == 99) print "task overn"; } [debug] the i value currently is 0 [extra] [debug] the i value currently is 1 [extra] [debug] the i value currently is 2 [extra] [debug] the i value currently is 3 [extra] [debug] the i value currently is 4 [extra] [debug] the i value currently is 5 [extra] [debug] the i value currently is 6 [extra] task over |