使用mktime在PHP 7.0中无法运行数月。
$month_options="";
for( $i = 1; $i <= 12; $i++ ) {
$month_num = str_pad( $i, 2, 0, STR_PAD_LEFT );
$month_name = date( 'F', mktime( 0, 0, 0, $i + 1, 0, 0, 0 ));
$selected="";
$month_options.$month_name."<br/>";
}
echo $month_options;
PHP 5.5中的结果
January
February
March
April
May
June
July
August
September
October
November
December
7.0的结果
January
January
January
January
January
January
January
January
January
January
January
请帮助我如何解决这个问题?...提前感谢
答案 0 :(得分:2)
在PHP 7中删除了here的mktime的最后一个参数Try this code snippet here 7.0.8是清晰的,你必须提供6个参数而不是7个。
https://developer.github.com/v3/repos/hooks/
is_dst
答案 1 :(得分:1)
注意PHP7 = is_dst参数已被删除。
$month_options="";
for( $i = 1; $i <= 12; $i++ ) {
/* $month_num = str_pad( $i, 2, 0, STR_PAD_LEFT ); -- there is no use for this line */
$month_name = date( 'F', mktime( 0, 0, 0, $i + 1, 0, 0)); // is_dst parameter has been removed.
/* $selected=""; -- there is no use for this line */
/* $month_options.$month_name."<br/>"; -- you are not correctly set this paramter */
$month_options .= $month_name."<br/>"; // so if you do like this, it will be correct
}
echo $month_options;
答案 2 :(得分:1)
为什么不使用DateTime对象呢?它们更易于使用,更易于操作。 DateTime可从PHP5.2及更高版本获得。
此代码段
$date = new DateTime("january");
for ($i = 1; $i <= 12; $i++) {
echo $date->format("F")."\n";
$date->modify("+1 months");
}
会输出
January
February
March
April
May
June
July
August
September
October
November
December