Q:

displaying list of dates for loop

i have this code..that will display a list of month for the current year and the first day of first month and second month 
$cur_year = date("Y");
$next_year = $cur_year+1;

for($m=1; $m<=12; ++$m)
{
$monthName=date('F', mktime(0, 0, 0, $m, 1)).''; 
$monthNumber=date('m', mktime(0, 0, 0, $m, 1)).''; 
$nextmonth=$monthNumber+1;

echo "$monthName<br />";
echo "$cur_year-$monthNumber-01<br />";
echo "$cur_year-$nextmonth-01<br /><br />";
}

i would like to be display like this
January
2017-01-01
2017-02-01

February
2017-02-01
2017-03-01

up to December

December
2017-12-01
2018-01-01

current ouput
January
2017-01-01
2017-2-01

February
2017-02-01
2017-3-01

up to December

December
2017-12-01
2017-13-01

A:

Use date() function in PHP
<? php
$cur_year  = date('Y');
$next_year = $cur_year + 1;

for ($m = 1; $m <= 12; ++$m)
{
    $monthName  = date('F', mktime(0, 0, 0, $m, 1));
    $currentMonthText = date('Y-m-d', mktime(0, 0, 0, $m, 1));
    $nextMonthText    = date('Y-m-d', mktime(0, 0, 0, $m + 1, 1));

    echo $monthName, '<br />', PHP_EOL;
    echo $currentMonthText, '<br />' .  PHP_EOL;
    echo $nextMonthText, '<br />' .  PHP_EOL;
}

