I have a simple array with some products to display in a html table. array
Array
(
[0] => Array
(
[item] => Hp-Probook
[opening_qty] => 2
[sold] => 10
)
[1] => Array
(
[item] => Hp-5420s
[opening_qty] => 8
[sold] => 4
)
[2] => Array
(
[item] => Dell-Inspiron
[opening_qty] => 15
[sold] => 10
)
[3] => Array
(
[item] => MacBook-Air-Pro
[opening_qty] => 2
[sold] => 10
)
[4] => Array
(
[item] => MacBook-Pro
[opening_qty] => 2
[sold] => 1
)
)
Here I need To display some specified products separately for example mac-book series separately in table Like
| name | qty | sold |
-----------------------------------
| Hp-Probook | 2 | 10 |
| Hp-5420s | 8 | 4 |
| Dell-Inspiron | 15 | 10 |
-----------------------------------
| Total | 25 | 24 |
-----------------------------------
|MacBook-Air-Pro | 5 | 5 |
| MacBook-Pro | 2 | 1 |
-----------------------------------
| total | 7 | 6 |
I try to Unset the specific values from first foreach and after total row make next foreach
<?php
$totalQty = 0;
$totalSold = 0;
foreach ($product as $key=>$value) {
if($value['item'] =='MacBook-Air-Pro'||$value['item'] =='MacBook-Pro') {
unset($product[$key]);
}
?>
<tr>
<td><?php echo $value['item'] ?></td>
<td><?php echo $value['opening_qty'] ?></td>
<td><?php echo $value['sold'] ?></td>
</tr>
<?php $totalQty += $value['opening_qty']; $totalSold += $value['sold'];?>
<?php } ?>
<tr>
<td>Total</td>
<td><?php echo $totalQty; ?></td>
<td><?php echo $totalSold; ?></td>
</tr>
This display all Products Like normal foreach and the Unset even didn't work, confused to display the removed(unset) rows in next foreach. is any alternative way to do this Thanks,