我想按鍵排序關聯數組。我使用ksort函數,但返回1而不是array.Below是我的代碼。按鍵排序關聯數組
$states=array("DD"=>"Daman and Diu", "LD"=>"Lakshdweep", "DN"=>"Dadra
and nagar haveli", "AN"=>"Andaman and Nicobar island", "SK"=>"Sikkim",
"MZ"=>"Mizoram", "GA"=>"Goa", "PY"=>"Puduchery", "CH"=>"Chandigarh",
"ML"=>"Meghalaya", "AR"=>"Arunachal Pradesh", "TR"=>"Tripura",
"HP"=>"Himanchal Pradesh", "NL"=>"Nagaland", "PB"=>"Punjab",
"CG"=>"Chattisgarh", "JK"=>"Jammu and Kashmir", "UA"=>"Uttrakhand",
"HR"=>"Haryana", "JH"=>"Jharkhand", "KL"=>"Kerela", "MN"=>"Manipur" ,
"AS"=>"Assam", "RJ"=>"Rajasthan", "MP"=>"Madhya Pradesh",
"KA"=>"Karnataka", "BR"=>"Bihar", "OR"=>"Orissa", "GJ"=>"Gujrat",
"AP"=>"Andhra Pradesh", "TN"=>"TamilNadu", "DL"=>"Delhi",
"MH"=>"Maharastra", "WB"=>"WestBengal", "UP"=>"UttarPradesh",
);
$states = ksort($states);
print_r($states);
輸出我得到的是:1
我想數組,而不是1
不知道函數應該如何工作:閱讀[在手冊中](http://php.net/ksort)! –
'ksort($ states)''而不是'$ states = ksort($ states)' –
@ÁlvaroG.Vicario好的我知道了 –