PHP: Populating an array with the names of the next 12 months

后端 未结 8 2174
遇见更好的自我
遇见更好的自我 2020-12-03 18:45
for($x=0; $x<12; $x++)
{
    $month = mktime(0, 0, 0, date(\"m\")+$x, date(\"d\"),  date(\"Y\"));
    $key = date(\'m\', $month);
    $monthname = date(\'F\', $mo         


        
8条回答
  •  情话喂你
    2020-12-03 19:31

    Given 2592000 is 30 days.

    $month_time = 60*60*24*30; // 30 Days
    for($x=0; x<12; $x++)
    {
         $time = time()+($month_time*$x);
         $key = date('m', $time);
         $month[$key] = date('F', $time);
    }
    

    In an answer on StackOverflow, can't find it right now, someone compared the performance of multiple methods of creating a time 1 week from now. Directly using numbers was much more efficient than any other method.

提交回复
热议问题