I have a purchase table in a mall. There are orders in the purchase table. Some orders have the same products as other orders. Then the amount field inside is the purchase quantity of the product in the order. I want to determine if this order is the same as the purchase quantity of the product in the order. If the ID of a certain product is the same, the quantity in the amount field will be superimposed. What should I do?
array(
[0]=>
'pid'=>7,
'amount'=>1,
[1]=>
'pid'=>7,
'amount'=>2,
[2]=>
'pid'=>8,
'amount'=>1,
)
For example, in this array, there are two pid values that are the same. I will add the combined values to form this array
array(
[0]=>
'pid'=>7,
'amount'=>3,
[1]=>
'pid'=>8,
'amount'=>1,
)
Use pid as the key of the new array
Write a loop, judge whether there are the same ones based on pid, merge them, and finally generate a new array OK
I have solved it myself, it is too complicated to think about it
//The code is as follows, I hope it will be helpful to you.
$orderInfo = array(
);
foreach ($orderInfo as $k=>$v)