Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.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 7.0 mktime不工作_Php - Fatal编程技术网

PHP 7.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

在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_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