現在の月に基づいて月を表示する必要があります。したがって、7 月の場合は、次の 4 か月 (たとえば、「8 月」、「9 月」、「10 月」、「11 月」) のみを返します。
これどうやってするの?
$mnth = date('F');
$mnth_arr = array("january","febuary","march","april","may","june","july","august","september","october","november","december");
現在の月に基づいて月を表示する必要があります。したがって、7 月の場合は、次の 4 か月 (たとえば、「8 月」、「9 月」、「10 月」、「11 月」) のみを返します。
これどうやってするの?
$mnth = date('F');
$mnth_arr = array("january","febuary","march","april","may","june","july","august","september","october","november","december");
これは、 DateTimeクラスを使用すると非常に簡単です。
$now = new \DateTime();
$interval = new \DateInterval('P1M');
$period = new \DatePeriod($now->add($interval), $interval, 4);
foreach($period as $date){
echo $date->format('F') . "<br/>";
}
出力:-
8月
9月
10月
11
月 12月
これを行うには、相対的なオフセットで strtotime を使用できます。
// get the next four months.
$ref = strtotime("+1 month");
for($x =0; $x<4; $x++){
echo date("F", $ref)."\n";
$ref = strtotime("+1 month", $ref);
}
$key = array_search($mnth, $mnth_arr);
for($key; $key<$key+4; $key++)
{
echo $mnth_arr[$key];
}