$match = DiraChatLog::where('status','=','Match')
->selectRaw('DATE(created_at) as date, COUNT(1) as cnt') // created_at here is datetime format, only need the date portion using `DATE` function
->orderBy("date")
->groupBy("date")
->get() // return result set (collection) from query builder
->pluck('cnt') // only need the cnt column
->values() // array_values
->all(); // convert collection to array
但我必须稍微更改我的代码才能获得另一个日期值,当我使用我的代码
时$matchs = DiraChatLog::where('status','=','Match')->whereBetween('date_access', [$request->from, $request->to])->get();
// $array[] = [];
foreach ($matchs as $key => $match) {
$day = substr($match->date_access, 0, 10);
if(isset($array[$day]))
{
$array[$day]++;
} else
{
$array[$day] = 1;
}
$match = $array;
}
现在我如何将它们变成阵列?例如它应该是[" 2018-03-04",3]等等,具有以下日期和价值..我该怎么做?我这样做的原因是因为当我插入值以在highcharts上查看时,第一种方式工作,但是第二种方式不能查看