日期遍历
function date_range($date1,$date2){
$timestamp1=strtotime($date1);
$timestamp2=strtotime($date2);
$days=($timestamp2-$timestamp1)/86400+1;
$date=[];
for($i=0;$i<$days;$i++){
$date[]=date('Y-m-d',$timestamp1+(86400*$i));
}
return $date;
}
年月遍历
function range_year_month($startYear = 2022, $startMonth = 7, $endYear = 2023, $endMonth = 10) {
$arr = [];
for ($i = $startYear; $i <= $endYear; $i++) {
for ($j = (($i == $endYear && $startYear < $endYear) ? 1 : $startMonth); $j <= ($i == $endYear ? $endMonth : 12); $j++) {
$arr[] = [
'year' => $i,
'month' => $j,
'yearMonth' => $i . '-' . \str_pad($j, 2, '0', \STR_PAD_LEFT),
];
}
}
return $arr;
}