I use php array_rand to select 1 random record from array, Example:
$style_class = array("st_style1","st_style2","st_style3","st_style4");
$random_class = array_rand($style_class, 1);
$div_class = $style_class[$random_class];
The issue is that sometimes it gives a same record several times, and as I use only 4 records it happens quiet often (using “array_rand” is not neccesary) .
Example:
st_style1,
st_style2,
st_style2,
st_style2,
st_style4,
st_style2 …
Is there a way to solve this issue, so two same record would not get displayed two times in a row.
For example
st_style2, st_style4, st_style2, st_style1, st_style3, st_style2, st_style1 …
The simpliest solution is to keep track of the latest one and keep calling random until you get something different. Something like:
Then use the
$styles[]array in order. It should not have any duplicates