<?php
$data = [
['id' => 1, 'date_inserted' => '2020-09-06', 'marketplace' => 'Etsy', 'total_stickers' => 11, 'total_orders' => 8, 'total_value' => 41.619999999999997],
['id' => 2, 'date_inserted' => '2020-09-06', 'marketplace' => 'Woo', 'total_stickers' => 2, 'total_orders' => 1, 'total_value' => 7.9800000000000004],
['id' => 3, 'date_inserted' => '2020-09-06', 'marketplace' => 'eBay', 'total_stickers' => 44, 'total_orders' => 40, 'total_value' => 115.63],
['id' => 4, 'date_inserted' => '2020-09-07', 'marketplace' => 'Etsy', 'total_stickers' => 8, 'total_orders' => 4, 'total_value' => 34.920000000000002],
['id' => 5, 'date_inserted' => '2020-09-07', 'marketplace' => 'Woo', 'total_stickers' => 9, 'total_orders' => 3, 'total_value' => '52.90'],
['id' => 6, 'date_inserted' => '2020-09-07', 'marketplace' => 'eBay', 'total_stickers' => 23, 'total_orders' => 21, 'total_value' => 58.030000000000001]
];
$result = [];
foreach (array_column($data, 'date_inserted') as $date) {
foreach (array_filter($data, function($v) use ($date) {
return $v['date_inserted'] === $date;
}) as $item) {
$result[$date][$item['marketplace']] = [
'id' => $item['id'],
'total_stickers' => $item['total_stickers'],
'total_orders' => $item['total_orders'],
'total_value' => $item['total_value']
];
}
}
print_r($result);
- Output for 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
- Array
(
[2020-09-06] => Array
(
[Etsy] => Array
(
[id] => 1
[total_stickers] => 11
[total_orders] => 8
[total_value] => 41.62
)
[Woo] => Array
(
[id] => 2
[total_stickers] => 2
[total_orders] => 1
[total_value] => 7.98
)
[eBay] => Array
(
[id] => 3
[total_stickers] => 44
[total_orders] => 40
[total_value] => 115.63
)
)
[2020-09-07] => Array
(
[Etsy] => Array
(
[id] => 4
[total_stickers] => 8
[total_orders] => 4
[total_value] => 34.92
)
[Woo] => Array
(
[id] => 5
[total_stickers] => 9
[total_orders] => 3
[total_value] => 52.90
)
[eBay] => Array
(
[id] => 6
[total_stickers] => 23
[total_orders] => 21
[total_value] => 58.03
)
)
)
preferences:
126.46 ms | 411 KiB | 5 Q