回答編集履歴
1
修正
answer
CHANGED
@@ -8,24 +8,18 @@
|
|
8
8
|
function check_month($date)
|
9
9
|
{
|
10
10
|
$now = new DateTime();
|
11
|
+
$now_month = $now->format('Y') * 12 + $now->format('n');
|
11
12
|
$dt = new DateTime($date);
|
12
|
-
$
|
13
|
+
$dt_month = $dt->format('Y') * 12 + $dt->format('n');
|
13
14
|
|
14
|
-
switch ($diff) {
|
15
|
-
case 0:
|
16
|
-
|
15
|
+
$diff = $dt_month - $now_month;
|
17
|
-
case 1;
|
18
|
-
return '来月';
|
19
|
-
case 2:
|
20
|
-
|
16
|
+
return (boolean) (0 <= $diff && $diff < 3);
|
21
|
-
default :
|
22
|
-
return null;
|
23
|
-
}
|
24
17
|
}
|
25
18
|
|
26
|
-
|
19
|
+
var_dump(check_month('2017-02-18')); // false
|
20
|
+
var_dump(check_month('2017-03-18')); // true
|
27
|
-
|
21
|
+
var_dump(check_month('2017-04-18')); // true
|
28
|
-
|
22
|
+
var_dump(check_month('2017-05-18')); // true
|
29
|
-
|
23
|
+
var_dump(check_month('2017-06-18')); // false
|
30
24
|
|
31
25
|
```
|