Home > Backend Development > PHP Tutorial > A method that displays each month within a certain period of time and returns an array consisting of these months_PHP Tutorial

A method that displays each month within a certain period of time and returns an array consisting of these months_PHP Tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 15:18:42
Original
883 people have browsed it

Copy code The code is as follows:

/**
* Generate a month array from the start month to the end month
* This method is modeled after Dang Zihao’s getDateArr() method
* @param unknown_type $start
* @param unknown_type $end
*/
function getMonthArr($start, $end)
{
$start = empty($start) ? date('Y-m',strtotime('-1 month')) : $start;
$end = empty($end) ? date( 'Y-m') : $end;

//Convert to timestamp
$st = strtotime($start.'-01');
$et = strtotime($end. '-01');

$t = $st;
$i = 0;
while($t <= $et)
{
//Accumulate here The calculation formula for the total number of seconds in each month: the timestamp seconds on the 1st of the previous month minus the timestamp seconds of the current month
//I don’t understand what I want to say
$d[$i] = trim(date('Y-m',$t),' ');
$t += strtotime('+1 month', $t)-$t;
$i++;
}
return $d;
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325458.htmlTechArticleCopy code The code is as follows: /** * Generate a month array from the starting month to the ending month* This method is modeled after the party Zihao getDateArr() method * @param unknown_type $start * @param unknown_type...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Why does it still jump after returning false?
From 1970-01-01 08:00:00
0
0
0
Optimize table indexes in MySQL
From 1970-01-01 08:00:00
0
0
0
Why can't I install it?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template