$canada_territories = array("British Columbia" => "British Columbia", "Manitoba" => "Manitoba", "New Brunswick" => "New Brunswick", "Newfoundland and Labrador" => "Newfoundland and Labrador", "Nova Scotia" => "Nova Scotia", "Northwest Territories" => "Northwest Territories", "Nunavut" => "Nunavut", "Ontario" => "Ontario", "Prince Edward Island" => "Prince Edward Island", "Quebec" => "Quebec", "Saskatchewan" => "Saskatchewan", "Yukon" => "Yukon");
print_r($canada_territories);
Array ([British Columbia [Manitoba]] => British Columbia [Manitoba] => Manitoba [New Brunswick] => New Brunswick [Newfoundland and Labrador] => Newfoundland and Labrador [Nova Scotia] => Nova Scotia [Northwest Territories] => Northwest Territories [Nunavut] => Nunavut [Ontario] => Ontario [Prince Edward Island] => Prince Edward Island [Quebec] => Quebec [Saskatchewan] => Saskatchewan [Yukon] => Yukon)
ritish哥倫比亞[馬尼托巴]是它開始猶豫了,加入下一個數組項
是什麼原因造成的一部分嗎?
我想建立這個數組來填充一個下拉表單,我對數組還不夠了解,我甚至真的需要將兩個不列顛哥倫比亞數組添加到數組中以便能夠循環遍歷它們嗎?
這是我經常使用,但它通常具有鍵和值,我設置,在這種情況下,我需要顯示以下值的兩倍,我通常表現出2個不同的值
foreach ($state_array as $sid => $statename) {
print '<option value=' . $sid . $selected . '>' . $statename . '</option>';
}
UPDATE
我不是包裝與標籤,它顯示了我如何張貼在鍍鉻,當我查看源代碼,它實際上是正確的
在這種情況下,因爲你不需要鑰匙那麼你可以定義數組沒有密鑰,因爲混亂。在這種情況下,如果使用foreach($ array作爲$ key => $ array),那麼$ key將是整數數組索引(因爲如果不指定鍵,PHP會自動添加從零開始的數組索引)。 – 2009-07-30 22:17:58