I have an array
which can have any no. of elements in it. Now i want to loop this array and create design such that each li
can have 15 elements inside it , next set of li
will be created based of multiples of 15's elements.
Now my array has exact 15 elements and the code i am trying creating 2 li
, which it should create only 1 li
.
May be my logic is too bad or I am missing anything.
Here is my code:-
<?php $result = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15); ?>
<div class="slide">
<?php $design = '<ul class="slides"><li><div class="MainSlider">';
foreach($result as $key=>$row)
{
$design .= '<div class="MainSliderPic">'.$key.'</div>';
if(($key+1)% 15 == 0){
$design .= '</div></li><li><div class="MainSlider">';
}
if(count($result) == $key+1){
$design .= '</div></li></ul>';
}
}
echo $design;
?>
</div>