PHP 7.0 mktime不工作
在PHP7.0中使用mktime无法工作数月PHP 7.0 mktime不工作,php,Php,在PHP7.0中使用mktime无法工作数月 $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_op
$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;
结果为7.0
January
January
January
January
January
January
January
January
January
January
January
请帮助我如何重新选择此问题?。提前感谢注意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;
$month_options=”“;
对于($i=1;$i很清楚,最后一个参数is_dst
of已在PHP7中删除,您必须给出6个参数,而不是7个
为什么不改用DateTime对象呢?它们更容易使用,也更容易操作。DateTime可从PHP5.2及以上版本获得
这个片段
$date = new DateTime("january");
for ($i = 1; $i <= 12; $i++) {
echo $date->format("F")."\n";
$date->modify("+1 months");
}
$month_num有什么用?为什么在mktime中使用$i+1?它没有使用,我忘了注释那一行。..sorryas per docs“is_dst参数已删除。”
<?php
ini_set('display_errors', 1);
$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));
$selected = "";
$month_options .= $month_name . "<br/>";
}
echo $month_options;
$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