Array ( [0] => 12 [1] => 17 [2] => 17 [3] => 17 [4] => 17 [5] => 3 [6] => 3 [7] => 3 [8] => 3 [9] => 3 ) Array ( [0] => 12 [4] => 17 [9] => 3 ) Array ( [12] => 2 [17] => 1 [3] => 2 )
1、处理产品数组,拿到产品id
2、合并重复的产品
3、
$i = 0; foreach ($arr as $key => $value){ $i++; echo $i; if($i%2==0){ $c = "1"; }else{ $c = "2"; } $c1[$value] = $c; //$c1['class'] = $c; //$c2[] = $c1; //echo $value.$c."<br>"; } echo "<pre>"; print_r ($c1); echo "</pre>";
4、
<style> .a1{background-color:#FFFFFF} .a2{background-color:#FCF4F0} </style> <tr class="<?php echo "a".$c1[$bv['sid']];?>">
把原来的数组(数组一)做处理,去除重复的产品id,并加上奇偶的属性,是为数组二
在数组一的循环里调用数组二,因为数组二里有产品的奇偶属性(即class样式)
这样的话,产品a,产品b,产品c,一目了然