在python數組排序我有一個很完善的情況如下:自創建字母
list = [('wr', ['A1']), ('wr-qA', ['A3']), ('wr,w', ['A4']), ('wr-mw', ['A2']), ('wrs', ['A6']), ('wrD', ['A8']), ('wrS', ['A7']), ('wr.w', ['A5']), ('=k', ['A10']), ('Dd', ['A9'])]
alphabet = " -,.AjawbpfmnrhHxXsSqkgtTdD=/()[]<>{}'*#I1234567890&@"
Sorted_list = sorted(list, key=lambda (v, k): [alphabet.index(c) for c in v])
print Sorted_list
Output = [('wr', ['A1']), ('wr-mw', ['A2']), ('wr-qA', ['A3']), ('wr,w', ['A4']), ('wr.w', ['A5']), ('wrs', ['A6']), ('wrS', ['A7']), ('wrD', ['A8']), ('Dd', ['A9']), ('=k', ['A10'])]
我如何可以做同樣的PHP中:
$list = array('wr' => 'A1', 'wr-qA' => 'A3', 'wr,w' => 'A4', 'wr-mw' => 'A2', 'wrs' => 'A6', 'wrD' => 'A8', 'wrS' => 'A7', 'wr.w' => 'A5', '=k' => 'A10', 'Dd' => 'A9');
PHP中的數組是什麼? – 2011-06-16 09:40:33
用作鍵的字符串是不同書寫文字的轉錄。根據給定的字母排序它們會給你一個詞典。 – Preys 2011-06-16 09:49:37
您還在使用Python中的元組列表,但在PHP中使用哈希列表?這是打算? – 2011-06-16 09:51:08