I have an array that looks like this:
[
{
"date":"2015-07-10",
"count":"1"
},{
"date":"2015-07-11",
"count":"3"
}
]
Which is given by the following Eloquent query:
$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();
How can I check if a certain date is already in the array? I've tried the following, but it returns false
(i.e. that the value isn't in the array, even though it is):
return in_array("2015-07-10", $posts);
You can use array_column
in this case.
return in_array("2015-07-10", array_column($posts, 'date'));
DOCS
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With