我在我的網站上有一個下拉菜單,我希望列出所有美國州。我有一系列的狀態,但我似乎無法將它們全部加載到我的<option>
標記中。下面是前15個州的數組和我的<select>
代碼。最終下拉將鏈接到每個狀態的單獨頁面,並顯示該狀態的圖像(這就是爲什麼我在每個狀態陣列中都有一個「img」)的原因。我下載的唯一州是阿拉斯加州,阿肯色州,科羅拉多州,特拉華州,佛羅里達州,夏威夷州和伊利諾伊州。狀態foreach循環未列出所有狀態
<?php
$states = array();
$states['AL'] = array (
"name" => "Alabama",
"img" => "http://getwidgetsfree.com/images/state_png/al.png"
);
$states['AK'] = array (
"name" => "Alaska",
"img" => "http://getwidgetsfree.com/images/state_png/ak.png"
);
$states['AZ'] = array (
"name" => "Arizona",
"img" => "http://getwidgetsfree.com/images/state_png/az.png"
);
$states['AR'] = array (
"name" => "Arkansas",
"img" => "http://getwidgetsfree.com/images/state_png/ar.png"
);
$states['CA'] = array (
"name" => "California",
"img" => "http://getwidgetsfree.com/images/state_png/ca.png"
);
$states['CO'] = array (
"name" => "Colorado",
"img" => "http://getwidgetsfree.com/images/state_png/co.png"
);
$states['CT'] = array (
"name" => "Connecticut",
"img" => "http://getwidgetsfree.com/images/state_png/ct.png"
);
$states['DE'] = array (
"name" => "Delaware",
"img" => "http://getwidgetsfree.com/images/state_png/de.png"
);
$states['DC'] = array (
"name" => "District of Columbia",
"img" => "http://pharmacoding.com/dendreon/provenge/images/dc.png"
);
$states['FL'] = array (
"name" => "Florida",
"img" => "http://getwidgetsfree.com/images/state_png/fl.png"
);
$states['GA'] = array (
"name" => "Georgia",
"img" => "http://getwidgetsfree.com/images/state_png/ga.png"
);
$states['HI'] = array (
"name" => "Hawaii",
"img" => "http://getwidgetsfree.com/images/state_png/hi.png"
);
$states['ID'] = array (
"name" => "Idaho",
"img" => "http://getwidgetsfree.com/images/state_png/id.png"
);
$states['IL'] = array (
"name" => "Illinois",
"img" => "http://getwidgetsfree.com/images/state_png/il.png"
);
$states['IN'] = array (
"name" => "Indiana",
"img" => "http://getwidgetsfree.com/images/state_png/in.png"
);
?>
<select>
<?php
foreach($states as $state) {
echo "<option value='state.php?id=" . $state["id"] . ">" . $state["name"] . "</option>";
};
?>
</select>
你曾經在'foreach'循環中定義了'$ state [「id」]'嗎? – esswilly