I have an array:
Array
(
[0] => Array
(
[id] => 81
[placed] => 2013-09-19 16:32:53
[sub_total] => 786
)
[1] => Array
(
[id] => 80
[placed] => 2013-09-19 16:32:06
[sub_total] => 780
)
[2] => Array
(
[id] => 79
[placed] => 2013-09-18 17:06:48
[sub_total] => 786
)
[3] => Array
(
[id] => 78
[placed] => 2013-09-18 17:05:02
[sub_total] => 756
)
[4] => Array
(
[id] => 77
[placed] => 2013-09-17 17:02:53
[sub_total] => 786
)
[5] => Array
(
[id] => 76
[placed] => 2013-09-16 17:02:53
[sub_total] => 756
)
)
Is it possible to group this data by date and summarize subtotal amount to get output array:
Array
(
[0] => Array
(
[placed] => 2013-09-19
[sub_total] => 786 + 780
)
[2] => Array
(
[placed] => 2013-09-18
[sub_total] => 786 + 756
)
[3] => Array
(
[placed] => 2013-09-17 17:02:53
[sub_total] => 786
)
[4] => Array
(
[placed] => 2013-09-16 17:02:53
[sub_total] => 756
)
)
Fiddle
Credits: The initial array used on this fiddle was taken from the answer by Jason OOO below.
You can have that kind of array at querying time. Something like
after that you can use a use foreach to work with each day's data!
I tested this also: http://phpfiddle.org/main/code/rzv-ngp
Try using sub query