I have the following code for selecting a random item out of an array each time a foreach loops through it's cycle.
<?php $variables = array('success', 'warning', 'info', 'danger'); ?>
<?php foreach($os->list as $list): $var = 'success'; ?>
<div class="progress-bar progress-bar-<?php echo $variables[array_rand($variables)]; ?>" style="width: <?php echo $list->metrics->visits; ?>%" title="<?php echo $list->os.' '.$list->version; ?>">
<span class="sr-only"><?php echo $list->metrics->visits; ?>%</span>
</div>
<?php endforeach; ?>
My only problem is that one time it chooses success
and then the next time it chooses success
you then can't tell the difference in the data. I would be okay if it selected something like:
success, info, danger, success, danger, info
Just not:
success, info, info, danger, success, success
Where two items end up side by side.
Is there a way to do this or am I wasting my time?
UPDATE
I though this up but i'm not sure where to go with it:
<?php foreach($os->list as $list): $var = 'success'; ?>
<?php
if($var){
$var1 = $var;
$var = $variables[array_rand($variables)];
if($var == $var1){
}
}
?>
<div class="progress-bar progress-bar-<?php echo $var; ?>" style="width: <?php echo $list->metrics->visits; ?>%" title="<?php echo $list->os.' '.$list->version; ?>">