Question

So I have an array

$super = array(8,9,10,11,12,20,21); 

I want to display first value for one hour in my website

after one hour display second one and etc.

after array reaches the end "21" it resets and starts to display first value

echo $super [0]

wait for one hour $super change to

$super[1]
next hour
 $super[2] 
and etc.

after

$super == $super[21] 
reset

 $super to  $super[0] 

I could use next(), current(), reset() functions, but I can't figure out how to loop them with delay.

Was it helpful?

Solution

Enjoy server-side static version:

$super = array(8,9,10,11,12,20,21); // Array can be extended
$h = date('H') ; //Current hour. Server time

$start_day_element = 0 ; //Offset, from what element days start.

echo $super[($h + $start_day_element)%count($super)] ;

But of course, page must be refreshed to see updated value.

OTHER TIPS

its awkward

user javascript settimeout to execute a js function with ajax

eg:setTimeout("somefun();", 5000);

where 5000 is the time delay

function somefun(){
    $("#msgSpan").load("site.com/somepage.php");
}

where "#msgSpan" is the id of the element where you display the array values

implement the logic to return array values accordingly in somepage.php

u can use php sessions to record current array index and for every next request you increment the array index

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top