DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,503 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Cover image for How to get all months from the year  using in Laravel
Vickyvn
Vickyvn

Posted on • Updated on

How to get all months from the year using in Laravel

$month = [];

for ($m=1; $m<=12; $m++) {
     $month[] = date('F', mktime(0,0,0,$m, 1, date('Y')));
}

print_r($month);
Enter fullscreen mode Exit fullscreen mode

date('F') will get result current month of the year. example October.
so with the help of mktime(0,0,0,2, 1, date('Y')) we will get output February.
so we replace 2 to $m in for each and get answer in $month array.
we will get output like this.

Array ( 
 [0] => January
 [1] => February 
 [2] => March
 [3] => April
 [4] => May
 [5] => June
 [6] => July
 [7] => August
 [8] => September
 [9] => October
 [10] => November
 [11] => December 
)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Take a look at this:

Settings

Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. πŸ›