1

我有一个数组,无法真正缩小打印所有内容的正确方法。

大批:

$month = Array(
    "1" => "January",
    "2" => "February",
    "3" => "March",
    "4" => "April",
    "5" => "May",
    "6" => "June",
    "7" => "July",
    "8" => "August",
    "9" => "September",
    "10" => "October",
    "11" => "November",
    "12" => "December"
);

我试过的:

function monthList() {
    require "config.php";
        echo '<select name="month" title="Choose A Month">';
    foreach ($month as $i => $value) {
        echo '<option value="'.the_month_#_here.'">'.$month[$i].'</option>';
    }
        echo '</select>';
}

哪个可以很好地提取名称,但我将如何提取数组中与其关联的数字?这就是我需要的option value

4

3 回答 3

3
function monthList() {
    require "config.php";
        echo '<select name="month" title="Choose A Month">';
    foreach ($month as $i => $value) {
        echo '<option value="'.$i.'">'.$value.'</option>';
    }
        echo '</select>';
}
于 2012-07-25T22:06:11.290 回答
1

采用

echo '<option value="'.$i.'">'.$value.'</option>';

代替

echo '<option value="'.the_month_#_here.'">'.$month[$i].'</option>';
于 2012-07-25T22:06:24.957 回答
0

试试这个希望这会有所帮助:)。

   function monthList() {
        require "config.php";
            echo '<select name="month" title="Choose A Month">';
        foreach ($month as $i => $value) {
            echo '<option value="'.$i.'">'.$value.'</option>';
        }
            echo '</select>';
    }

祝你好运。

于 2012-07-25T22:08:29.623 回答