我有以下数组,如果日期相同,我想增加数量。如何增加php中具有相同数组元素的值?
Array (
[0] => Array ([date] => 2016-02-02 [quantity] => 2)
[1] => Array ([date] => 2016-02-04 [quantity] => 1)
[2] => Array ([date] => 2016-02-05 [quantity] => 1)
[3] => Array ([date] => 2016-02-02 [quantity] => 1)
[4] => Array ([date] => 2016-02-03 [quantity] => 1)
[5] => Array ([date] => 2016-02-02 [quantity] => 2)
[6] => Array ([date] => 2016-02-03 [quantity] => 2)
[7] => Array ([date] => 2016-02-04 [quantity] => 2)
)
for example if 0 index having date 2016-02-02 and quantity 2,and same like 3rd index having same date but different quantity like wise 5th index. Now i want to add only the quantity if date are same and store into new array as
Array (
[0] => Array ([date] => 2016-02-02 [quantity] => 5)
[1] => Array ([date] => 2016-02-04 [quantity] => 3)
[2] => Array ([date] => 2016-02-05 [quantity] => 1)
[4] => Array ([date] => 2016-02-03 [quantity] => 3)
)
请解释一下如何在php中这样做。
感谢lot..Its工作良好。 – Raja
@Raja,很高兴为你效力,祝你好运 –