0

現在の年 (たとえば 2013 年) に過ぎ去った月 (1 月、2 月、10 月など) がないかどうかを確認するにはどうすればよいですか?

私はこれらのコード行を持っています、

# Set month array for the calendar.
$months_calender = array();

# Set current month and curren year.
$current_month = (int)date('m');
$current_year = (int)date('Y');

for($x = $current_month; $x < $current_month+12; $x++) $months_calender[] = date('M', mktime(0, 0, 0, $x, 1));

以下の月のリストを取得するには、

Array (
    [0] => Nov
    [1] => Dec
    [2] => Jan
    [3] => Feb
    [4] => Mar
    [5] => Apr
    [6] => May
    [7] => Jun
    [8] => Jul
    [9] => Aug
    [10] => Sep
    [11] => Oct )

次に、その月が属する年を印刷したいのですが、

foreach($months_calender as $index => $month_calender)
{
    if current year has no more Jan then print next year, for instance 2014
}

何か案は?

4

2 に答える 2

1

forステートメント内で年を取得できます

for($x = $current_month; $x < $current_month+12; $x++) {
    $months_calender[] = date('M', mktime(0, 0, 0, $x, 1));
    $years[] = date('Y', mktime(0, 0, 0, $x, 1));
}
于 2013-11-06T13:41:26.093 に答える
1
# Set month array for the calendar.
$months_calender = array();
$current_month = (int)date('m');

for($x = $current_month; $x < $current_month+12; $x++) {
    $time = mktime(0, 0, 0, $x, 1);
    $months_calender[] = array(date('M', $time), date('Y', $time));
}

foreach($months_calender as $monthYear) {
   list($month, $year) = $monthYear;
   echo "$month, $year\n";
}
于 2013-11-06T13:43:07.067 に答える