我有一个如下所示的数组:
[
{
"date":"2015-07-10",
"count":"1"
},{
"date":"2015-07-11",
"count":"3"
}
]
以下Eloquent查询给出:
$posts = Post::select(array(
DB::raw('DATE(`created_at`) as `date`'),
DB::raw('COUNT(*) as `count`')
))
->where('created_at', '>', Carbon::today()->subWeek())
->groupBy('date')
->orderBy('date', 'DESC')
->get()
->toArray();
如何检查数组中是否已存在某个日期?我尝试过以下操作,但它返回false
(即数组中的值不是,即使它是):
return in_array("2015-07-10", $posts);
答案 0 :(得分:5)