我正在研究一种过滤双精度值的方法,如下面的示例所示,数组中存在的are乘积基本上是双精度的,应该合并(用合并的值创建一个新键)。
该产品应通过api_id组合。
//old current array
[products] => Array
(
[product_5c7fb5f72f9d5_192] => Array
(
[record_id] => 84721
[api_id] => 192
[amount] => 12
[cost_price] => 3.36
)
[product_5c7fb5f72fe49_192] => Array
(
[record_id] => 84722
[api_id] => 177
[amount] => 1
[cost_price] => 1.09
)
[product_5c7fb5f7301b2_192] => Array
(
[record_id] => 84724
[api_id] => 192
[amount] => 24
[cost_price] => 6.72
)
[product_5c7fb5f7301b2_192] => Array
(
[record_id] => 84725
[api_id] => 192
[amount] => 24
[cost_price] => 6.72
)
)
// this should be new new array
[products] => Array
(
[product_5c7fb5f72f9d5_192] => Array
(
[record_id] => 84721
[api_id] => 192
[amount] => 60//new value
[cost_price] => 16.8//new value
)
[product_5c7fb5f72fe49_192] => Array
(
[record_id] => 84722
[api_id] => 177
[amount] => 1
[cost_price] => 1.09
)
)
答案 0 :(得分:2)
您可以使用<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
:
array_reduce