Returns an array composed of the months by a method that shows each month in a certain period of time. _ PHP Tutorial

Source: Internet
Author: User
Returns an array composed of the months. The copy code is as follows: *** generate the array of months from the start month to the end month * this method is modeled by the getDateArr () method * @ paramunknown_type $ start * @ paramunknown_type The code is as follows:


/**
* Generates an array of months from the start month to the end month.
* This method is similar to the getDateArr () method of party Zihao.
* @ 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)
{
// Formula for calculating the total number of seconds accumulated here: the timestamp number of seconds in the previous month minus the timestamp number of the current month
// Do not understand what you want to do
$ D [$ I] = trim (date ('Y-M', $ t ),'');
$ T + = strtotime ('+ 1 month', $ t)-$ t;
$ I ++;
}
Return $ d;
}

The http://www.bkjia.com/PHPjc/325458.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/325458.htmlTechArticle code is as follows:/*** generate the array of months from the start month to the end month * this method is modeled after party Zi Hao getDateArr () METHOD * @ param unknown_type $ start * @ param unknown_type...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.