This method is applicable to scenarios where you need to analyze data by calendar month without ** calculating the start and end timestamps of each natural month in the past N months, including the number of months in the current month * @ paraminteger $ max, the default value is 6 * @ paramstring $ monthstr. The third subscript of the returned array (the expression of the specific month) * @ returnarray array (starting from month ).
Applicable to scenarios where you need to analyze data by calendar month without/*** calculate the start and end timestamps of each calendar month in the past N months, including the number of months in the current month * @ param integer $ max, the default value is 6 * @ param string $ monthstr. The third subscript of the returned array (the expression of the specific month) * @ return array. each subarray is in the form of array (starting from month ).
Applicable to scenarios where data needs to be analyzed by calendar month <无>
/*** Calculates the start and end timestamps of each natural month in the past N months, including the current month * @ param integer $ max number of months, the default value is 6 * @ param string $ monthstr. The third subscript of the returned array (the expression of the specific month) * @ return array. each subarray is in the form of array (the start timestamp of the month, month End timestamp, month name) */function month_offset ($ max = 6, $ monthstr = 'ym') {if ($ max <= 0) {return false ;} $ base = date ('Y-m-01 '); $ Y = 1; $ mo = array (); $ mo [0] [0] = strtotime ($ base ); $ mo [0] [1] = time (); $ mo [0] [2] = date ('ymm'); while ($ y <$ max) {$ mo [$ y] [0] = strtotime (date (' Y-m-01 ', strtotime ($ base.'-'. $ y. 'month'); $ mo [$ y] [1] = $ y = 1? $ Mo [0] [0]: $ mo [$ Y-1] [0]; $ mo [$ y] [2] = date ($ monthstr, $ mo [$ y] [0]); $ y ++;} return array_reverse ($ mo);} var_export (month_offset (3); exit; /* array (0 => array (0 => 1425139200, 1 => 1427817600, 2 => '123',), 1 => array (0 => 1503, 1 => 1430409600, 2 => '20140901',), 2 => array (0 => 1504, 1 => 1430409600, 2 => '20160901 ',),) [Finished in 0.1 s] */