<?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);
preferences:
26.43 ms | 406 KiB | 5 Q