Home >Backend Development >PHP Tutorial >Implement a function that pushes down n months from a specified time_PHP tutorial
Author: bjbs_270
I used the function as mentioned in the monthly report statistics some time ago. I combined it with others to use the mktime() function and wrote one, but I kept getting errors afterwards, which was very frustrating. I took some time over the weekend to write one for use. I hope it will be useful to some villagers.
PHP code:-------------------------------------------------- ------------------------------------
/*
* Author: Xin Deng
* Function: Implement a function to push down N months from a specified time
* month($ymd,$len) $ymd time, $len pushes out several months
* $ymd =2005-01-01;
*/
function month($ymd=,$len=12){
$month = array();
$lang = $lang."";
if($ymd){//Judge 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