0

Is possible to make for loop function for php, that works like this

function hit(){

}

function forLoop($function, $times) {

for($x = 0; $x < $times; $x++) {
    $function;
}

$this->forLoop($function, 5);
ALeifsson
  • 70
  • 7

1 Answers1

0

This can be done with the call_user_func function:

function hit(){
    echo "hello !";
}

function forLoop($function, $times) {

    for($x = 0; $x < $times; $x++) {
        call_user_func($function);
    }
}

forLoop('hit', 5);
Mureinik
  • 297,002
  • 52
  • 306
  • 350