Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP日期:如何检查今年是否没有过去的月份?_Php_Date_Php 5.4_Mktime - Fatal编程技术网

PHP日期:如何检查今年是否没有过去的月份?

PHP日期:如何检查今年是否没有过去的月份?,php,date,php-5.4,mktime,Php,Date,Php 5.4,Mktime,我如何检查今年(例如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 &

我如何检查今年(例如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));
然后我要打印该月所属的年份

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

有什么想法吗?

你可以在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));
}
for($x=$current\u month;$x<$current\u month+12;$x++){
$months_calendar[]=日期('M',mktime(0,0,0,$x,1));
$years[]=日期('Y',mktime(0,0,0,x,1));
}
#设置日历的月份数组。
$months\u calendar=array();
$current_month=(int)date('m');
对于($x=$current\u month;$x<$current\u month+12;$x++){
$time=mktime(0,0,0,$x,1);
$months\u calendar[]=数组(日期($M',$time),日期($Y',$time));
}
foreach($monthYear){
列表($month,$year)=$monthYear;
回显“$month,$year\n”;
}

日期('n')应获取当前月份。。。你可能想退房,或者我完全误解了???只需在未来12个月的当前时间基础上再加1个月。因此,当您打印年度时,它将反映年度变化。
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));
}