2

So I have a multidimensional array, containing 36 arrays.

I want for a page to display an "Item of the day" in the way that each array is only available for a specific date, and then not again until all the other array have been featured on other days first. The collection doesn't necessarily need to be randomized.

This is not a duplicate of this because in my case I cannot edit or even do direct queries on any database, nor can I write to files or anything else to permanently mark that an item has been featured.

I can however store perhaps a variable containing the initiation date, which could be used as a reference point to somehow calculate which array should be displayed on the current date.

However, math was never my strong suite so I don't know how to do such very very complex calculations. Nor do I have the programming heft to know if this concept is even the best one.

What do you suggest?

Community
  • 1
  • 1
Emphram Stavanger
  • 4,158
  • 9
  • 35
  • 63

2 Answers2

5

I'm not sure if this counts, but you could do modulo operation on the current date:

$messages = array('hi, how are you', 'nice weather eh?', 'get lost!');
$idx = floor(time() / 86400) % count($messages);

echo $messages[$idx];

Every day it will pick one for that whole day; then move to the next, etc. At the end it goes back to the beginning.

It's sort of random what the first item will be, but after that it's sequential.

Ja͢ck
  • 170,779
  • 38
  • 263
  • 309
0

I'd reckon you'd have to store the data outside of the program/page code, in order to check against it (dates, etc) each time/each day you load the page.

ShWebb
  • 39
  • 3