因为我们可以在C++中定义循环模板,以使代码更短:
#define fo(a,b,c) for( a = ( b ); a < ( c ); ++ a )
有没有办法在PHP中做同样的事情?
发布于 2011-05-29 01:08:48
发布于 2011-05-29 01:20:24
不如这样吧:
function my_macro($a, $b, $c) {
$args = func_get_args();
array_shift($args);
array_shift($args);
array_shift($args);
return call_user_func_array("something_horrifically_long_involving_{$a}_{$b}_and_{$c}", $args);
}
发布于 2014-12-31 09:18:19
CCPP似乎是可用的最接近的东西:
#define macroFunction(op1,op2,op3) ((int)op1/((int)op2+(int)op3))
#define hash_hash # ## #
#define showCExamples 1
#if showCExamples
//Reference: http://en.wikipedia.org/wiki/C_preprocessor#Token_concatenation
#define MYCASE(item,id) \
case id: \
item##_##id = id;\
break
switch(x) {
MYCASE(widget,23);
}
https://stackoverflow.com/questions/6163053
复制相似问题