1 回答
TA贡献1802条经验 获得超6个赞
无需尝试使查询复杂化,您只需稍微更改应用程序 (PHP) 代码即可。获取数据库中可用日期的查询结果。现在,在 PHP 代码中,只需检查该日期的计数是否可用。如果是,使用计数,否则设置为零。
// Change the SQL query result to an array with date as key, and count as value
$reacts_mod = array_combine(array_column($reacts, 'reactedDate'),
array_column($reacts, 'count'));
// Now prepare the $result
$result = array();
// Loop over input dates here
foreach ($dates as $dt) {
// If you have count obtained from the query result, then consider that else 0
if ( isset($reacts_mod[$dt]) ) {
$result[] = $reacts_mod[$dt];
} else {
$result[] = 0;
}
// Note: PHP7 code would be simply:
// $result[] = $reacts_mod[$dt] ?? 0;
}
- 1 回答
- 0 关注
- 497 浏览
添加回答
举报