I am trying to collect all the current days of the week and of the month in an array. It should be easy, but as much as I search, I can't find a solution. For example putting today as the day, the result I need is something like this:
$daysInWeek = [31,1,2,3,4,5,6];
$daysInMonth = [1,2,3,4,5,6,7,...,28];//Note here that are febrary, and need to return 28, not 31
I write this code, But I think that Carbon can make it easier:
$weekStartDate = Carbon::now()->startOfWeek();
$monthStartDate = Carbon::now()->startOfMonth();
$daysInWeek[] = $weekStartDate->day;
for ($i=0; $i < 6; $i++) {
$daysInWeek[] = $weekStartDate->addDay(1)->day;
}
$daysInMonth[] = $monthStartDate->day;
$lastMonthDay = Carbon::now()->month()->daysInMonth; //This return 31 days, not 28.
for ($i=0; $i < $lastMonthDay-1; $i++) {
$daysInMonth[] = $monthStartDate->addDay(1)->day;
}