Show laps of a for in time intervals

0

The following is more than anything a query. We have a simple cycle:

for ($i = 1; $i <= 10; $i++){
  echo $i."</br>";
}

As we already know at the time of executing this code, all the results will be displayed once and in this case a count of 1 to 10, what I would like to know is which language, perhaps AJAX or JAVASCRIPT , or some function of PHP could show each of the laps of the cycle for , is say that s show the 1, then the 2, and so, I know it seems something AJAX but I do not handle it much, but I'm still open to suggestions with this language, the point is that there are time intervals between each round of the for , since I am handling a for that requires many laps and the browser hangs, and I wanted to see if this could be a solution .

    
asked by Jalkhov 27.12.2018 в 22:02
source

1 answer

1

you could try a recursive function in Javascript:

function recursiva( i, maximo )
{
    if ( i > maximo ) return;
    console.log(i)
    i = i + 1;
    setTimeout( function(){ recursiva(i, maximo); }, 1000 );
}

recursiva(1, 10);
    
answered by 27.12.2018 в 22:10