PHP
1<?php
2
3$start_date = "2019-11-12";
4$end_date = "2019-12-31";
5
6$datetime1 = date_create($start_date);
7$datetime2 = date_create($end_date);
8
9$interval = date_diff($datetime1, $datetime2);
10$diff = intval($interval->format('%a'));
11
12$dim1 = [];
13$dim2 = [];
14
15for ($i = 0; $i <= $diff; $i++) {
16 $day = date("Y-m-d", strtotime($start_date . " +{$i} days"));
17 $dow = date("N", strtotime($day));
18 if ($dow === "1") {
19 if ($dim2) {
20 $dim1[] = $dim2;
21 }
22 $dim2 = [$day];
23 } else {
24 $dim2[] = $day;
25 }
26}
27$dim1[] = $dim2;
28var_dump($dim1);
出力
array(8) {
[0]=>
array(6) {
[0]=>
string(10) "2019-11-12"
[1]=>
string(10) "2019-11-13"
[2]=>
string(10) "2019-11-14"
[3]=>
string(10) "2019-11-15"
[4]=>
string(10) "2019-11-16"
[5]=>
string(10) "2019-11-17"
}
[1]=>
array(7) {
[0]=>
string(10) "2019-11-18"
[1]=>
string(10) "2019-11-19"
[2]=>
string(10) "2019-11-20"
[3]=>
string(10) "2019-11-21"
[4]=>
string(10) "2019-11-22"
[5]=>
string(10) "2019-11-23"
[6]=>
string(10) "2019-11-24"
}
[2]=>
array(7) {
[0]=>
string(10) "2019-11-25"
[1]=>
string(10) "2019-11-26"
[2]=>
string(10) "2019-11-27"
[3]=>
string(10) "2019-11-28"
[4]=>
string(10) "2019-11-29"
[5]=>
string(10) "2019-11-30"
[6]=>
string(10) "2019-12-01"
}
[3]=>
array(7) {
[0]=>
string(10) "2019-12-02"
[1]=>
string(10) "2019-12-03"
[2]=>
string(10) "2019-12-04"
[3]=>
string(10) "2019-12-05"
[4]=>
string(10) "2019-12-06"
[5]=>
string(10) "2019-12-07"
[6]=>
string(10) "2019-12-08"
}
[4]=>
array(7) {
[0]=>
string(10) "2019-12-09"
[1]=>
string(10) "2019-12-10"
[2]=>
string(10) "2019-12-11"
[3]=>
string(10) "2019-12-12"
[4]=>
string(10) "2019-12-13"
[5]=>
string(10) "2019-12-14"
[6]=>
string(10) "2019-12-15"
}
[5]=>
array(7) {
[0]=>
string(10) "2019-12-16"
[1]=>
string(10) "2019-12-17"
[2]=>
string(10) "2019-12-18"
[3]=>
string(10) "2019-12-19"
[4]=>
string(10) "2019-12-20"
[5]=>
string(10) "2019-12-21"
[6]=>
string(10) "2019-12-22"
}
[6]=>
array(7) {
[0]=>
string(10) "2019-12-23"
[1]=>
string(10) "2019-12-24"
[2]=>
string(10) "2019-12-25"
[3]=>
string(10) "2019-12-26"
[4]=>
string(10) "2019-12-27"
[5]=>
string(10) "2019-12-28"
[6]=>
string(10) "2019-12-29"
}
[7]=>
array(2) {
[0]=>
string(10) "2019-12-30"
[1]=>
string(10) "2019-12-31"
}
}
配列1つ目を〜
のところは自力で頑張ってください。