Good afternoon. I fight not the first day of the task ...
Displays the goods in the form of a table:
Name Code Quantity
Through the foreach loop, the repeating item is displayed in the table, but it is necessary that the entire repeating item (by name and code) is no longer output, and the number is added to what is already there.
<?php foreach ($product_data as $product) { ?> <tr> <td><?php echo $product['name']; ?></td> <td><?php echo $product['sku']; ?></td> <td class="text-right"><?php echo $product['quantity']; ?></td> </tr> <?php } ?> Here is my code. Tell me, please, how to be?
Update
My attempts:
if(!in_array($product['name'], $sum)) { $sum['name'][] = $product['name']; } if(!in_array($product['sku'], $sum)) { $sum['sku'][] = $product['sku']; } $sum['name'] = array_map("unserialize", array_unique( array_map("serialize", $sum['name']))); $sum['sku'] = array_map("unserialize", array_unique( array_map("serialize", $sum['sku']))); Accordingly, I declared $sum above as an array. Collects everything as it should. Only 1 name remains, but how does the quantity combine the same?