问题描述
目前我有一个数据保存在 MysqL 的 json 列中。我想显示数据,但我需要合并重复值并对特定键的值求和。数组的键是动态的。这是示例响应。
[
[
{
"FeeType": "Commission","FeeAmount": {
"CurrencyCode": "EUR","CurrencyAmount": 1.75
}
},{
"FeeType": "refundCommission","CurrencyAmount": -0.35
}
}
],[
{
"ChargeType": "Tax","ChargeAmount": {
"CurrencyCode": "EUR","CurrencyAmount": 0
}
},{
"ChargeType": "Tax",{
"ChargeType": "Principal","CurrencyAmount": -24.95
}
},{
"ChargeType": "ReturnShipping","CurrencyAmount": 0
}
}
],[
{
"FeeType": "Commission","CurrencyAmount": -0.35
}
}
],"CurrencyAmount": -24.95
}
}
],{
"FeeType": "ShippingChargeback","CurrencyAmount": 3.35
}
}
],[
{
"ChargeType": "ShippingTax",{
"ChargeType": "ShippingCharge","CurrencyAmount": -3.99
}
}
],[
{
"PromotionId": "DE Core Free Shipping 2018\/04\/24 20-00-00","PromotionType": "PromotionMetaDataDeFinitionValue","PromotionAmount": {
"CurrencyCode": "EUR",{
"PromotionId": "DE Core Free Shipping 2018\/04\/24 20-00-00","CurrencyAmount": 1.99
}
}
],{
"ChargeType": "ShippingTax","CurrencyAmount": -1.99
}
},
........
我想要达到的是有这样的结果
[
ShippingCharge => totalofShippingCharges
Tax => totalofalltax
Principal => totalofall pricipla,Commission => totalofallcommissions
]
我试过是这样的
$result = collect($myarray)
->groupBy('FeeType')
->map(function( $value) {
return array_merge(...$value->toArray());
})->values()->toArray();
但它只是创建原始数组的新副本。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)