<style>
.mm,.tt,.dd{
width: 350px;
}
.dd{
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
}
.dd li{
list-style-type: none;
height: 48px;
width: 48px;
line-height: 48px;
text-align: center;
}
</style>
<?php
$aa = getRili('2022-1-1','2022-12-31');
foreach ($aa as $week){
echo "<div class='mm'>";
echo "<div class='tt'>".$week['tit']."</div>";
echo "<div class='dd'>";
foreach ($week['days'] as $key =>$day){
echo "<li>".$day['text']."</li>";
}
echo "</div></div>";
}
function getRili($start='',$end=''){
$start = !empty($start)? $start:date('Y-01-01');
$end = !empty($end)? $end:date('Y-12-31');
$list = [];
while(strtotime($start)<=strtotime($end)){
$m = date('m',strtotime($start));
$d = date('d',strtotime($start));
$t = date('t',strtotime($start));
$weekDay = date('w',strtotime($start));
$week = get_week(strtotime($start));
for ($w=0;$w<=6;$w++){
if(($w==0 && $d=='01')){
$list[$m]['tit'] = date('n月',strtotime($start));
}
if($w==$weekDay){
$list[$m]['days'][] = [
'text' => $d,
'day' => $start,
'w' => $week
];
}
if($w<$weekDay && $d=='01'){
$list[$m]['days'][] = [
'text' => '--',
'day' => $start,
'w' => $week
];
}
if($d==$t && $weekDay<$w){
$list[$m]['days'][] = [
'text' => '--',
'day' => $start,
'w' => $week
];
}
}
$start = date('Y-m-d',strtotime("$start +1 Day"));
}
return $list;
}
function get_week($date){
$w = date('W',$date);
$m = date('n',$date);
return $w==1?($m==12?53:1):($w>=51?($m==1?1:$w):$w);
}