0

I would like this countdown to start at 10 then count down to 1, but for the user to see it in real time - this script waits 50 seconds and then shows me all the numbers (1-10). What am I doing wrong here?

<body>
Countdown<br><br>
<div id="countdown">
<?php
for($i = 10; $i >= 1; $i--) {
   echo $i;
   sleep(5);
};
?>
</div>
<script> 
setTimeout((document.getElementById('countdown').reload()),1000);

</script>

</body>

I tried the above example

Jonathan
  • 1
  • 1
  • 1
    You can't do a realtime countdown with PHP. PHP runs before any data is sent to the browser. You'll want just javascript for a countdown script. – aynber Dec 19 '22 at 19:26

0 Answers0