2017-04-27 5 views
1

PHP 7.0でmktimeを使用して月が稼働していません。 PHPでPHP 7.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; 

結果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 

でこの問題をresloveする方法を私を助けてください?...おかげで、事前に

+0

month_num $の使用は何ですか?なぜmktimeで$ i + 1を作っていますか? – bfahmi

+0

その使用されていない私はその行にコメントすることを忘れないでください。 – sridhard

+0

ドキュメントごとhttp://php.net/manual/en/function.mktime.php * "is_dstパラメータが削除されました" * –

答えて

2

それは、最後のパラメータmktimeis_dstはPHP 7で削除されましたhereをクリアリー書かれている、あなたは、6つのパラメータの代わりに、7使用しないのはなぜ

Try this code snippet here 7.0.8

<?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; 
+0

.. – sridhard

+0

@sridhardようこそ。:) –

1

PHP7 =は_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; 
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 

Live demo

関連する問題