So I have this array that consists of
array (size=3)
0 =>
array (size=2)
'id' => string '46' (length=2)
'ship_product_code' => string '122' (length=6)
'purchase_order_number' => string 'PO-1' (length=4)
1 =>
array (size=2)
'id' => string '47' (length=2)
'ship_product_code' => string '123' (length=6)
'purchase_order_number' => string 'PO-2' (length=4)
2 =>
array (size=2)
'id' => string '50' (length=2)
'ship_product_code' => string '124' (length=6)
'purchase_order_number' => string 'PO-2' (length=4)
PO-1 //PO Number
122 // Product Code
<tr> <td> </td> </tr>//another td for space
PO-2 //PO Number
123 // Product Code
124 // Product Code
if(count($products)>0){
$i=0;
foreach($products as $v){
$PDFCONTENT .= '<tr>
<td align="center" width="7%"> </td>
<td align="center" width="50%">'.$v['purchase_order_number'].'</td>
</tr>';
$i++;
$PDFCONTENT .= '
<tr>
<td align="center" width="7%">'.$i.'</td>
<td align="center" width="50%">'.$v['ship_product_code].'</td>
<td align="center" width="7%">'.number_format($v['qty']).'</td>
<td width="7%"> </td>
</tr>
<tr>
<td></td>
</tr>
';
}
}
PO-1
122
PO-2
123
PO-2
124
Use following code snippet. With same PO Number we have now only one record.
$fianlProducts = [];
if(count($products)>0){
foreach($products as $row){
$fianlProducts[$row['purchase_order_number']]['purchase_order_number'] = $row['purchase_order_number'];
$fianlProducts[$row['purchase_order_number']]['ship_product_code'][] = $row;
}
$i=0;
foreach($fianlProducts as $v){
$PDFCONTENT .= '<tr>
<td align="center" width="7%"> </td>
<td align="center" width="50%">'.$v['purchase_order_number'].'</td>
</tr>';
foreach($v['ship_product_code'] as $w){
$i++;
$PDFCONTENT .= '
<tr>
<td align="center" width="7%">'.$i.'</td>
<td align="center" width="50%">'.$w['ship_product_code'].'</td>
<td align="center" width="7%">'.number_format($w['qty']).'</td>
<td width="7%"> </td>
</tr>
<tr>
<td></td>
</tr>
';
}
}
}