Create an Array of the Last 30 Days Using PHP

前端 未结 5 1809

I am trying to create an array starting with today and going back the last 30 days with PHP and I am having trouble. I can estimate but I don’t know a good way of doing it

5条回答
  •  伪装坚强ぢ
    2020-12-20 13:47

    You can use time to control the days:

    for ($i = 0; $i < 30; $i++)
    {
        $timestamp = time();
        $tm = 86400 * $i; // 60 * 60 * 24 = 86400 = 1 day in seconds
        $tm = $timestamp - $tm;
    
        $the_date = date("m/d/Y", $tm);
    }
    

    Now, within the for loop you can use the $the_date variable for whatever purposes you might want to. :-)

提交回复
热议问题