i have an array like this the sructure of my array, i need to sum "weight" value and push them to the end of array list with key "total_weight":
{
"730": [{
"qty": "1",
"product_id": 8,
"product_name": "NIKE As M Dry Tee Legend 2.0 - Black\/Black\/Matte Silver [XL]",
"product_price": 299000,
"product_image": "1604906748nike-as-m-dry-tee-legend-20-blackblackmatte-silver-xl.jpg",
"product_slug": "nike-as-m-dry-tee-legend-20-blackblackmatte-silver-xl",
"weight": 100,
"seller_origin": 730
},
{
"qty": "1",
"product_id": 7,
"product_name": "Skipping jump rope Tali Skiping Loncat Speeds Anti Slip 100676 LX",
"product_price": 25000,
"product_image": "1604907088skipping-jump-rope-tali-skiping-loncat-speeds-anti-slip-100676-lx.jpg",
"product_slug": "skipping-jump-rope-tali-skiping-loncat-speeds-anti-slip-lx-1006",
"weight": 200,
"seller_origin": 730
},
{
"qty": 2,
"product_id": 6,
"product_name": "Kappa Track Suit Jacket - Black Black L",
"product_price": 230000,
"product_image": "1602820947kappa-track-suit-jacket-black-black-l.jpg",
"product_slug": "kappa-track-suit-jacket-black-black-l",
"weight": 100,
"seller_origin": 730
}
],
"3641": [{
"qty": "1",
"product_id": 4,
"product_name": "Groot Figure Guardian Pot Marvel",
"product_price": 46999,
"product_image": "1606719651groot-figure-guardian-pot-marvel.jpg",
"product_slug": "groot-figure-guardian-pot-marvel",
"weight": 300,
"seller_origin": 3641
}]
}
i want generate summary of "weight" group by key of array like this:
{
"730": [{
"qty": "1",
"product_id": 8,
"product_name": "NIKE As M Dry Tee Legend 2.0 - Black\/Black\/Matte Silver [XL]",
"product_price": 299000,
"product_image": "1604906748nike-as-m-dry-tee-legend-20-blackblackmatte-silver-xl.jpg",
"product_slug": "nike-as-m-dry-tee-legend-20-blackblackmatte-silver-xl",
"weight": 100,
"seller_origin": 730
},
{
"qty": "1",
"product_id": 7,
"product_name": "Skipping jump rope Tali Skiping Loncat Speeds Anti Slip 100676 LX",
"product_price": 25000,
"product_image": "1604907088skipping-jump-rope-tali-skiping-loncat-speeds-anti-slip-100676-lx.jpg",
"product_slug": "skipping-jump-rope-tali-skiping-loncat-speeds-anti-slip-lx-1006",
"weight": 200,
"seller_origin": 730
},
{
"qty": 2,
"product_id": 6,
"product_name": "Kappa Track Suit Jacket - Black Black L",
"product_price": 230000,
"product_image": "1602820947kappa-track-suit-jacket-black-black-l.jpg",
"product_slug": "kappa-track-suit-jacket-black-black-l",
"weight": 100,
"seller_origin": 730
},
"total_weight":400
],
"3641": [{
"qty": "1",
"product_id": 4,
"product_name": "Groot Figure Guardian Pot Marvel",
"product_price": 46999,
"product_image": "1606719651groot-figure-guardian-pot-marvel.jpg",
"product_slug": "groot-figure-guardian-pot-marvel",
"weight": 300,
"seller_origin": 3641
},
"total_weight":300
]
}
how to i get generate array like this by sum all of weight value of array? i have try to sum of weight value and push them to the end of list array