【发布时间】:2013-11-06 13:32:26
【问题描述】:
如何检查当前年份(例如 2013 年)是否不再有过去的月份(例如一月、二月...十月),然后做点什么?
我有这几行代码,
# 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
}
有什么想法吗?
【问题讨论】:
-
date('n');应该得到当前月份...您可能想查看date,还是我完全误解了??? -
未来 12 个月只需将当前时间加 1 个月即可。因此,当您打印出年份时,它将反映年份的变化。