优艾设计网

php数组重复数据的处理?

优艾设计网 https://www.uibq.com 2023-06-20 07:50 出处:网络 作者:磨皮美容教程
array(4) { [0] => array(7) { [\"goodsId\"] => string(2) \"15\" [\"goodsNo\"] => string(13) \"9311770592581\" [\"goodsName\"] => string(37) \"DCS超级水润泡沫洗面/洁面乳\" [\"price\"] =>

array(4) { [0] => array(7) { ["goodsId"] => string(2) "15" ["goodsNo"] => string(13) "9311770592581" ["goodsName"] => string(37) "DCS超级水润泡沫洗面/洁面乳" ["price"] => string(5) "40.00" ["currency"] => string(2) "15" ["quantity"] => int(1) ["goods_tax_price"] => string(1) "0" } [1] => array(7) { ["goodsId"] => string(2) "16" ["goodsNo"] => string(13) "9327693000805" ["goodsName"] => string(21) "DCS超级营养精华" ["price"] => string(5) "10.00" ["currency"] => string(2) "15" ["quantity"] => string(1) "1" ["goods_tax_price"] => string(1) "0" } [2] => array(7) { ["goodsId"] => string(2) "17" ["goodsNo"] => string(13) "9327693000744" ["goodsName"] => string(18) "DCS超级营养水" ["price"] => string(5) "30.00" ["currency"] => string(2) "15" ["quantity"] => string(1) "1" ["goods_tax_price"] => string(1) "0" } [3] => array(7) { ["goodsId"] => string(2) "18" ["goodsNo"] => string(13) "9311770592505" ["goodsName"] => string(27) "DCS集中美白活力面膜" ["price"] => string(5) "40.00" ["currency"] => string(2) "15" ["quantity"] => string(1) "1" ["goods_tax_price"] => string(1) "0" } [4] => array(7) { ["goodsId"] => string(2) "18" ["goodsNo"] => string(13) "9311770592505" ["goodsName"] => string(27) "DCS集中美白活力面膜" ["price"] => string(5) "40.00" ["currency"] => string(2) "15" ["quantity"] => string(1) "2" ["goods_tax_price"] => string(1) "0" } }

把数组里的goodsId重复的商品信息合成一个,个数为quantity的总和(同样商品总和)

结果应为:

array(4) { [0] => array(7) { ["goodsId"] => string(2) "15" ["goodsNo"] => string(13) "9311770592581" ["goodsName"] => string(37) "DCS超级水润泡沫洗面/洁面乳" ["price"] => string(5) "40.00" ["currency"] => string(2) "15" ["quantity"] => int(1) ["goods_tax_price"] => string(1) "0" } [1] => array(7) { ["goodsId"] => string(2) "16" ["goodsNo"] => string(13) "9327693000805" ["goodsName"] => string(21) "DCS超级营养精华" ["price"] => string(5) "10.00" ["currency"] => string(2) "15" ["quantity"] => string(1) "1" ["goods_tax_price"] => string(1) "0" } [2] => array(7) { ["goodsId"] => string(2) "17" ["goodsNo"] => string(13) "9327693000744" ["goodsName"] => string(18) "DCS超级营养水" ["price"] => string优艾设计网_PS问答(5) "30.00" ["currency"] => string(2) "15" ["quantity"] => string(1) "1" ["goods_tax_price"] => string(1) "0" } [3] => array(7) { ["goodsId"] => string(2) "18" ["goodsNo"] => string(13) "9311770592505" ["goodsName"] => string(27) "DCS集中美白活力面膜" ["price"] => string(5) "40.00" ["currency"] => string(2) "15" ["quantity"] => string(1) "3" ["goods_tax_price"] => string(1) "0" }}


xymm敏敏 9小时前

二维数组去重,看看这个是否你想要个结果:http优艾设计网_PS交流://zhidao.baidu.com/link?...


asrwetwtw 9小时前

优艾设计网_PS论坛

说一个思路吧,用一个字典因为goodsId是唯一的, 所以k是goodsId遍历数组,如果字典里有goodsId则加上对应的数值,没有则把对应的数据放到字典里


0

精彩评论

暂无评论...
验证码 换一张
取 消