I have an array like this
$products_array = array('test product', 'test new product', 'test lipsum', 'test lorem', ....);
I just got the values from array like this
echo '<ul>';
foreach( $products_array as $product_array ) {
echo '<li>$product_array</li>';
}
echo '</ul>';
But here I want something dynamic. I want to add class name according to the value set by the user. Lets say user wants to show 5 lists in a row then the markup will be like this
<ul>
<li class="first">test product</li>
<li>test new product</li>
<li>test lipsum</li>
<li>test lorem</li>
<li class="last">test update</li>
<li class="first">test new product</li>
<li>test a product</li>
<li>test new lipsum</li>
<li>test lorem</li>
<li class="last">test new update</li>
</ul>
So here you can see at last means after each 5 post its adding class last and it is adding class first to the first list and after the fifith list blocks. So in this when user will set $class = 3 then it will add last class to the third block and the first will be added to the first and the list block just after the 3rd, 6th, 9th etc
I have done like this
$last = '4' //set 4. so for 4th,8th,12th it will add class last. and for 1st, 5th, 9th it will add class first
echo '<ul>';
$i = 0;
$count = count($products_array);
foreach( $products_array as $product_array ) {
$i++;
$class = '';
if( $i == $count ) {
$class = 'last';
}
echo '<li class='.$class.'>$product_array</li>';
}
echo '</ul>';
But its not working. So can somone tell me how to do this? Any help and suggestions will be really appreciable. Thanks