-1

I want to get the year-related months list into the array. for an example:

$months = array( 'January', 'February', 'March', 'April', 'May', 'June', 'July ', 'August', 'September', 'October', 'November', 'December', );

  • 2
    Please explain what is your problem – Rateb Habbab Sep 20 '21 at 17:38
  • 1
    Does this answer your question? [Displaying the list of months using mktime for the year 2012](https://stackoverflow.com/questions/10829424/displaying-the-list-of-months-using-mktime-for-the-year-2012) – jspit Sep 21 '21 at 06:42

1 Answers1

0

You can use Carbon package to get the result

public function getMonthListFromDate(Carbon $start, Carbon $to): array
{
    $months = [];

    foreach (CarbonPeriod::create($start, '1 month', $to) as $month) {
        $months[] = $month->format('F');
    }

    return $months;
}

enter image description here

keizah7
  • 649
  • 4
  • 18