get last 3 months from current month using php

后端 未结 4 1122
[愿得一人]
[愿得一人] 2021-01-27 19:58

I want to get last 3 months name from current month. For example current month is August. So, I want the datas like these June, July, August. I have tried this code echo d

4条回答
  •  耶瑟儿~
    2021-01-27 20:53

    You are actually on the right track by using date and strtotime functions. Expanding it below to your requirements:

    function getMonthStr($offset)
    {
        return date("F", strtotime("$offset months"));
    }
    
    $months = array_map('getMonthStr', range(-3,-1));
    

提交回复
热议问题