可以为php创建循环函数,其工作方式类似于
function hit(){
}
function forLoop($function, $times) {
for($x = 0; $x < $times; $x++) {
$function;
}
$this->forLoop($function, 5);
这可以通过call_user_func
函数完成:
function hit(){
echo "hello !";
}
function forLoop($function, $times) {
for($x = 0; $x < $times; $x++) {
call_user_func($function);
}
}
forLoop('hit', 5);