0

現在の月に基づいて月を表示する必要があります。したがって、7 月の場合は、次の 4 か月 (たとえば、「8 月」、「9 月」、「10 月」、「11 月」) のみを返します。

これどうやってするの?

$mnth = date('F');
$mnth_arr = array("january","febuary","march","april","may","june","july","august","september","october","november","december");
4

3 に答える 3

1

これは、 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月

于 2013-07-27T07:23:38.140 に答える
0

これを行うには、相対的なオフセットで 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);
 }
于 2013-07-27T07:23:03.747 に答える
0
$key = array_search($mnth, $mnth_arr);
for($key; $key<$key+4; $key++)
{
  echo $mnth_arr[$key];
}
于 2013-07-27T07:08:11.057 に答える