我们的软件在关联数组中提供购买的产品列表。我们需要组合这个数组并创建一个具有统一计数的新数组。然后,此阵列将用于为我们的结算部门创建采购清单。PHP组合并计数关联数组
样本数组:
Array
(
[0] => Array
(
[item] => Long Sleeve-Shirt & Hooded Sweatshirt
[quantity] => 1
[size] => Youth Small
[color] => Blue
)
[1] => Array
(
[item] => Long Sleeve-Shirt & Hooded Sweatshirt
[quantity] => 1
[size] => Adult Small
[color] => Red
)
[2] => Array
(
[item] => Hooded Sweatshirt Youth & Adult Sizes
[quantity] => 1
[size] => Youth Large
[color] => Blue
)
[3] => Array
(
[item] => Long Sleeve-Shirt & Hooded Sweatshirt
[quantity] => 1
[size] => Youth Small
[color] => Blue
)
}
综合阵列
Array
(
[0] => Array
(
[item] => Long Sleeve-Shirt & Hooded Sweatshirt
[quantity] => 2
[size] => Youth Small
[color] => Blue
)
[1] => Array
(
[item] => Long Sleeve-Shirt & Hooded Sweatshirt
[quantity] => 1
[size] => Adult Small
[color] => Red
)
[2] => Array
(
[item] => Hooded Sweatshirt Youth & Adult Sizes
[quantity] => 1
[size] => Youth Large
[color] => Blue
)
}
我将如何创建一个函数来第一阵列下结合,创建第二个阵列。我能想到的唯一的事情就是创建几个foreach循环,并慢慢打破列表。我没有使用关联数组和函数,我相信做多个foreach循环会很慢,并且可以做得更有效率。
这很好。你试过什么了? –
有没有问题?人们怎么回答?我可以帮你解决,但我不明白你想做什么。 – Ms01