所以我有这个数组
array (size=17)
'id' => string '21' (length=2)
'request_area' => string 'Area 1' (length=6)
'ship_product_code' => string '795919' (length=6)
'ship_product_description' => string 'BULBs' (length=5)
'qty' => string '2.0000' (length=6)
array (size=17)
'id' => string '22' (length=2)
'request_area' => string 'Area 1' (length=6)
'ship_product_code' => string '123' (length=3)
'ship_product_description' => string '321s' (length=4)
'qty' => string '3.0000' (length=6)
这些数组在里面
$product
我循环积数组并使用以下代码回显表
if(count($product)>0){
$i=0;
foreach($product as $v){
$i++;
$CONTENT.= '
<tr>
<td align="center" width="7%"> </td>
<td align="center" width="50%">'.$v['request_area'].'</td>
</tr>
<tr>
<td align="center" width="7%">'.$i.'</td>
<td align="center" width="50%">'.$v['ship_product_description'].'</td>
<td align="center" width="7%">'.number_format($v['qty']).'</td>
<td width="7%"> </td>
</tr>
';
}
}
上面代码的问题是,它将创建一个tr
Request Area
Item 1
Request Area
Item 2
我想要的是,它只打印一次请求区域,然后再打印项目。我该如何实现?
Request Area //only once
Item 1
Item 2
Item 3
// and so on
谢谢 :)
根据您的问题,如果尝试以下操作,它将为您提供所需的结果:
if(count($product)>0){
$i=0;
foreach($product as $v){
if($i == 0){
$CONTENT .= '<tr>
<td align="center" width="7%"> </td>
<td align="center" width="50%">'.$v['request_area'].'</td>
</tr>';
}
$i++;
$CONTENT.= '
<tr>
<td align="center" width="7%">'.$i.'</td>
<td align="center" width="50%">'.$v['ship_product_description'].'</td>
<td align="center" width="7%">'.number_format($v['qty']).'</td>
<td width="7%"> </td>
</tr>
';
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句