Author: bjbs_270 a period ago, I used the question-based function for one-month report statistics. I wrote one using the mktime () function, but it was always wrong and depressing. I would like to take some time over the weekend to write one for some villagers. PHP code: --------------------------------- SyntaxHig
Author: bjbs_270
Some time ago, I made a monthly report statistics and used the topic-like function. I wrote one using the mktime () function, but it was always wrong and depressing. I would like to take some time over the weekend to write one for some villagers.
PHP code :--------------------------------------------------------------------------------
/*
* Author: heart lamp
* Function: implements the function of pushing down N months from the specified time.
* Month ($ ymd, $ len) $ ymd Time, $ len released several months
* $ Ymd = 2005-01-01;
*/
Function month ($ ymd =, $ len = 12 ){
$ Month = array ();
$ Lang = $ lang ." ";
If ($ ymd) {// Determine whether the time format is correct
If (! Ereg ("([0-9] {4})-([0-9] {1, 2})-([0-9] {1, 2 })", $ ymd )){
Echo "";
Exit;
}
}
If ($ len ){
If (! Ereg ("[0-9] +", $ len )){
Echo $ lang ."";
Exit;
}
}
For ($ I = 0; $ I <$ len; $ I ++ ){
If ($ I = 0 ){
$ Mktime = $ ymd? Strtotime ($ ymd): time ();
}
$ Month [] = date ("Y-m", $ mktime); // you can design your desired format as needed.
$ Day = date ("t", $ mktime );
If ($ I = 0)
$ Reday = date ("d", $ mktime );
Else
$ Reday = $ day;
$ T1 = $ mktime;
$ Mktime = date ("Y-m-d", mktime (date ("H", $ t1), date ("I", $ t1 ), date ("s", $ t1), date ("m", $ t1), date ("d", $ t1)-$ reday, date ("Y ", $ t1 )));
$ Mktime = strtotime ($ mktime );
}
Return $ month;
}
$ Month = month ();
Foreach ($ month as $ key => $ v ){
Echo $ v ."
";
}
?>
--------------------------------------------------------------------------------
The effect is as follows:
2005-01
2004-12
2004-11
2004-10
2004-09
2004-08
2004-07
2004-06
2004-05
2004-04
2004-03
2004-02