我有一个数组:
Array
(
[0] => Array
(
[qty] => 2
[id] => 1
[name] => Name 1
[sku] => Model 1
[options] => Color: <em>Black (+10$)</em>. Memory: <em>32GB (+99$)</em>.
[price] => 209.00
)
[1] => Array
(
[qty] => 1
[id] => 1
[name] => Name 1
[sku] => Model 1
[options] => Color: <em>Black (+10$)</em>. Memory: <em>16GB</em>.
[price] => 110.00
)
[2] => Array
(
[qty] => 1
[id] => 3
[name] => Name 2
[sku] => Model 2
[options] =>
[price] => 100.00
)
)
第一步是找到相同的id。如果存在相同的 id 转换数组。是否可以获得输出数组(如果 id 相同,删除一个并将 qty 添加到另一个)?
Array
(
[0] => Array
(
[qty] => 3 // 2+1
[id] => 1
[name] => Name 1
[sku] => Model 1
[options] => Color: <em>Black (+10$)</em>. Memory: <em>32GB (+99$)</em>.
[price] => 209.00
)
[1] => Array
(
[qty] => 1
[id] => 3
[name] => Name 2
[sku] => Model 2
[options] =>
[price] => 100.00
)
)
谢谢!