I have a loop that should output a variable every 2 seconds, 10 times. I tried it like this, but it displays everything at once in 20 seconds. That is, she waits until the action is executed 10 times. And I need it so that if the loop runs once, then output once, and then after two seconds, print the second value.

<?php for ($i=0; $i <10 ; $i++) { echo $_POST['name']; echo $_POST['number']; sleep(2); } ?> 

    1 answer 1

    Using PHP in no way (although here is the output caching, but here, as I understand it, this is not the case). The essence of this scripting language is that it is first completely executed, and then returns the result to the web server for transmission to the client.

    For interactive in the browser window, use JavaScript.