Different css styling for last element of a php array -
when looping through array how can create different css div style last element output in array.
for($i=0;$i<=count($productid);$i++){if($productrank[$i]>0 ){ <? if (($productid[$i] % 2 ) && !( last element of array){ echo '<div class="centerboxcontentsfeatured centeredcontent vline " style="width:50%;">';} else { echo '<div class="centerboxcontentsfeatured centeredcontent " style="width:50%;">';} ?>
just check if last $productid
for(...) { if ($i === (count ($productid) - 1)) // last 1 -> special css } }
also, not use count()
in loop if don't have to. assign value before , use :
$count_temp = count ($productid); ($i = 0; $i < $count_temp; ++$i)
and use $count_temp again if if statement check if it's last element
answer comment :
how same method first element?
if ($i === 0)
or
// special css $i = 0 // start loop @ 1 instead of 0 ($i = 1; $i < $count_temp; ++$i)
Comments
Post a Comment