Yes, you'll need JavaScript for this. All PHP can do is emit the values to client-side code. Then it's up to the client-side code to display those values.
So, for example, your PHP code can populate a JavaScript array:
<script type="text/javaScript">
var values = <?php echo json_encode($php_variable); ?>;
</script>
In this case $php_variable
would be an array containing the values you want to display. Now your client-side code has an array called values
which it can iterate. You can use setTimeout
to schedule something to happen with a delay. Iterating over that array, it might look something like this:
var index = 0;
var displayValue = function () {
if (index >= values.length) { return; }
var value = values[index++];
// display "value" somewhere on your page
setTimeout(displayValue, 1000);
};
displayValue();
This should display each value in the array with 1-second increments. Note that I sort of glazed over the "display somewhere on your page" part, since that's up to you really. Where/how are you looking to display this? This works a little differently client-side than it does server-side, since the entire HTML document is already rendered. You need to identify where in that document you want to display the value and display it there, not just "echo" it.