1 回答
TA贡献1828条经验 获得超13个赞
有点斗志旺盛,但这应该可以了。$chart 变量将保存您要查找的内容。
// Assuming data is the "array for object in this format"
$dates = array_reduce($data, function ($dates, $record) {
if (!in_array($record['o_date']), $dates) {
$dates[] = $record['o_date'];
}
return $dates;
}, []);
$stores = array_reduce($data, function ($stores, $record) {
if (!in_array($record['storeName'], $stores)) {
$stores[] = $record['storeName'];
}
return $stores;
}, []);
$headers = $stores;
$headers[] = [ 'role' => 'annotation' ])
$chart = [ $headers ];
foreach ($dates as $date) {
$datapoint = [ $date ];
foreach ($stores as $store) {
$total = 0;
foreach ($data as $record) {
$isStore = $record['storeName'] === $store;
$isDate = $record['o_date'] === $date;
if($isStore && $isDate) {
$total += (float) $record['total_amount'];
}
}
$datapoint[] = $total;
}
$chart[] = $datapoint;
}
- 1 回答
- 0 关注
- 112 浏览
添加回答
举报