I am trying to get shuffle and only 19 items in a for each
loop. I used shuffle()
and if (++$i == 19) {break;}
, but the problem is one time it returns 12 items, one time 13, and another time 14. What did I do wrong?
Here is the code to check:
<?php
$i = 0;
shuffle($children);
foreach ($children as $child) {
if ($child['name_total'] > 0) {
?>
<li>
<?php echo ($child['filter_id'] == 2 ? "<span class='Verified'><i class='fa fa-check-circle'></i></span>" : ""); ?>
<div class="CatImg"><a title="<?php echo $child['name']; ?>" href="<?php echo $child['href']; ?>"><img alt="<?php echo $child['name']; ?>" src="<?php echo $child['thumb']; ?>"/></a></div>
<a title="<?php echo $child['name']; ?>" href="<?php echo $child['href']; ?>"><?php echo $child['name']; ?><span class="Total"><?php echo $child['name_total']; ?></span></a>
</li>
<?php
}
if (++$i == 19) {
break;
}
}
?>