Weekly Shuffle Array

I have a set of 4 HTML list elements, and I would like to shuffle the order that they appear once a week. I was wondering if anyone has a good, elegant solution there?

As always, I would be extremely grateful for any contribution you have.

UPDATE:

Unfortunately, even with the necessary .htaccess overrides, I just can’t get any srand () -based solutions to work on this particular server, but there is the following that could be used instead - at the moment it returns only one element list - how can I change it to show the four required? Once again, any ideas would be greatly appreciated :)

function RandomList($TimeBase, $QuotesArray){ $TimeBase = intval($TimeBase); $ItemCount = count($QuotesArray); $RandomIndexPos = ($TimeBase % $ItemCount); return $QuotesArray[$RandomIndexPos]; } $WeekOfTheYear = date('W'); $RandomItems = array( "<li><a href=\"#northern-germany\" title=\"Northern Germany\">North</a></li>","<li><a href=\"#southern-germany\" title=\"Southern Germany\">South</a></li>","<li><a href=\"#western-germany\" title=\"Western Germany\">West</a></li>","<li><a href=\"#eastern-germany\" title=\"Eastern Germany\">East</a></li>"); print RandomList($WeekOfTheYear, $RandomItems); 
+4
source share
1 answer

Here is a simple and, it seems to me, quite elegant solution that does not include storing values ​​in a database, setting up cronjobs and other boring things.

Suppose you have list items in $array :

 srand(date('W')); shuffle($array); srand(); 

Now your array is shuffled and will be shuffled in the same way as next Monday.

This problem has a problem: it does not work with the Suhosin patch (installed by default in Debian). However, now that you know about date('W') , it will be easy for you to find an alternative solution on your own.

EDIT: if you don't want to use your own pseudo-random number generator, but you have Suhosin installed, you can put the following line in your .htaccess :

php_value suhosin.srand.ignore 0

+2
source

All Articles