$styles = [
'grid-2h',
'grid-2h',
'grid-1',
'grid-1',
'grid-4',
'grid-4'
];
shuffle($styles);
$total = count($styles);
$trigger = 1;
$buffer = [];
while ($trigger) {
foreach ($styles as $k => $style) {
if (count($buffer) == $total) {
$trigger = 0;
break;
}
$next = $styles[$k+1] ?? ($total - 1);
$next == $style ?: $buffer[] = $style;
}
}
print_r( $buffer );