0

此 php 代码显示月份两次,而不是正常显示。请帮帮我

    <?php
  /**
   * 
   * Populationg the month dropdown list dynamically
   * generating the months from January to december
   */
echo '<select name="monthz">';
for($m = 1;$m <= 12; $m++){
$month = date("F", mktime(0, 0, 0, $m));
echo "<option value='$m'>$month</option>";
}
echo "</select>";
?>
4

2 回答 2

0

您缺少以下参数mktime()

$month = date('F', mktime(0, 0, 0, $m, 1, 2013);

除此之外,我看不出它会重复几个月的任何原因。

于 2013-05-31T08:26:41.733 回答
0

您的函数缺少Day参数mktime(),只需添加它。我还编辑了您的报价和双引号并连接

echo '<select name="monthz">';
for($m = 1;$m <= 12; $m++){
    $month = date("F", mktime(0, 0, 0, $m, 1));
                                         //^ this is the day
    echo '<option value="'.$m.'">'.$month.'</option>';
}
echo "</select>";

现场演示

于 2013-05-31T08:30:32.590 回答