This content originally appeared on DEV Community and was authored by Vickyvn
$month = [];
for ($m=1; $m<=12; $m++) {
$month[] = date('F', mktime(0,0,0,$m, 1, date('Y')));
}
print_r($month);
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
)
This content originally appeared on DEV Community and was authored by Vickyvn

Vickyvn | Sciencx (2021-10-19T04:47:41+00:00) How to get all months from the year using in Laravel. Retrieved from https://www.scien.cx/2021/10/19/how-to-get-all-months-from-the-year-using-in-laravel/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.