Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.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月数组原始值_Php_Arrays_Date - Fatal编程技术网

PHP月数组原始值

PHP月数组原始值,php,arrays,date,Php,Arrays,Date,我试图通过表单提交一个日期数组。我已经知道了如何将数字范围显示为一个月,但是表单提交的格式不对 工作: $Startmonth=date('n'); $monthArray = range(1,12); ?> <select class="bkwidgetdd" name="CIM" size="1"> <!-- CIM = CheckInMonth --> <?php fo

我试图通过表单提交一个日期数组。我已经知道了如何将数字范围显示为一个月,但是表单提交的格式不对

工作:

$Startmonth=date('n');
$monthArray = range(1,12);
?>

<select class="bkwidgetdd" name="CIM" size="1">
    <!-- CIM = CheckInMonth -->
    <?php
    foreach ($monthArray as $month) {
        $selected = ($month == $Startmonth) ? 'selected' : '';
        echo '<option '.$selected.' value="'.$month.'">'.$month.'</option>';
    }
    ?>
</select>
$Startmonth=日期('n');
$monthArray=范围(1,12);
?>
不工作:

$Startmonth=date('n');
$monthArray = array(1 => 'Jan', 2 => 'Feb', 3 => 'Mar', 4 => 'Apr', 5 => 'May', 6 => 'Jun', 7 => 'Jul', 8 => 'Aug', 9 => 'Sep', 10 => 'Oct', 11 => 'Nov', 12 => 'Dec');
?>

<select class="bkwidgetdd" name="CIM" size="1">
    <!-- CIM = CheckInMonth -->
    <?php
    foreach ($monthArray as $month) {
        $selected = ($month == $Startmonth) ? 'selected' : '';
        echo '<option '.$selected.' value="'.$month.'">'.$month.'</option>';
    }
    ?>
</select>
$Startmonth=日期('n');
$monthArray=array(1=>‘一月’、2=>‘二月’、3=>‘三月’、4=>‘四月’、5=>‘五月’、6=>‘六月’、7=>‘七月’、8=>‘八月’、9=>‘九月’、10=>‘十月’、11=>‘十一月’、12=>‘十二月’;
?>
我知道它正在崩溃,因为它将月份作为字符串而不是数字值提交。如何将其显示为月份,但提交为编号


非常感谢。

很接近,需要使用数组的键作为值:

foreach ($monthArray as $key => $month) {
    $selected = ($key == $Startmonth) ? 'selected' : '';
    echo '<option '.$selected.' value="'.$key.'">'.$month.'</option>';
}
foreach($monthArray作为$key=>$month){
$selected=($key==$Startmonth)?'selected':'';
回音“.$month.”;
}

您很接近,需要使用数组的键作为值:

foreach ($monthArray as $key => $month) {
    $selected = ($key == $Startmonth) ? 'selected' : '';
    echo '<option '.$selected.' value="'.$key.'">'.$month.'</option>';
}
foreach($monthArray作为$key=>$month){
$selected=($key==$Startmonth)?'selected':'';
回音“.$month.”;
}
请使用以下代码:

    $Startmonth=date('n');
    $monthArray = array(1 => 'Jan', 2 => 'Feb', 3 => 'Mar', 4 => 'Apr', 5 => 'May', 6 => 'Jun', 7 => 'Jul', 8 => 'Aug', 9 => 'Sep', 10 => 'Oct', 11 => 'Nov', 12 => 'Dec');
?>

<select class="bkwidgetdd" name="CIM" size="1">
     <!-- CIM = CheckInMonth -->
     <?php
          foreach ($monthArray as $key => $month){
              $selected = ($key == $Startmonth) ? 'selected' : '';
              echo '<option '.$selected.' value="'.$key.'">'.$month.'</option>';
          }
     ?>
</select>
$Startmonth=日期('n');
$monthArray=array(1=>‘一月’、2=>‘二月’、3=>‘三月’、4=>‘四月’、5=>‘五月’、6=>‘六月’、7=>‘七月’、8=>‘八月’、9=>‘九月’、10=>‘十月’、11=>‘十一月’、12=>‘十二月’;
?>
请使用以下代码:

    $Startmonth=date('n');
    $monthArray = array(1 => 'Jan', 2 => 'Feb', 3 => 'Mar', 4 => 'Apr', 5 => 'May', 6 => 'Jun', 7 => 'Jul', 8 => 'Aug', 9 => 'Sep', 10 => 'Oct', 11 => 'Nov', 12 => 'Dec');
?>

<select class="bkwidgetdd" name="CIM" size="1">
     <!-- CIM = CheckInMonth -->
     <?php
          foreach ($monthArray as $key => $month){
              $selected = ($key == $Startmonth) ? 'selected' : '';
              echo '<option '.$selected.' value="'.$key.'">'.$month.'</option>';
          }
     ?>
</select>
$Startmonth=日期('n');
$monthArray=array(1=>‘一月’、2=>‘二月’、3=>‘三月’、4=>‘四月’、5=>‘五月’、6=>‘六月’、7=>‘七月’、8=>‘八月’、9=>‘九月’、10=>‘十月’、11=>‘十一月’、12=>‘十二月’;
?>

需要使用$key==$Startmonth键进行检查,需要使用$key==$Startmonth键进行检查,感谢您的响应,Suresh标记了另一个,因为它是第一个出现的。尽管如此,还是很感激!谢谢你的回复,苏雷什,因为它是第一个,所以打了另一个标记。尽管如此,还是很感激!