<?php
$res = [];
$start_m = [1, 2, 3,4,5,6,7,8,9,10,11,12];
$init_arr = [0,0,0,0,0,0,0];
foreach ($start_m as $v) {
$row = [];
for ($i = 0; $i <= 5; $i++) {
$row[] = $init_arr;
}
$res[$v] = $row;
}
$weekarray = array(7,1,2,3,4,5,6);
foreach ($start_m as $v) {
$d = date('t', strtotime(date("Y-${v}-m")));
$sum = 0;
foreach (range(1, $d) as $key => $vo) {
$row_index = intval($sum / 7);
$w = date('w', strtotime(date("Y-${v}-${vo}")));
if ($sum == 0) {
$sum += $weekarray[$w];
}else{
$sum++;
}
$res[$v][$row_index][$w] = $vo;
}
}
echo json_encode($res);
其映射关系 一维是行 二维是具体的日 $weekarray=array(“日”,“一”,“二”,“三”,“四”,“五”,“六”);
|