0

我正在尝试更改我的购物车软件的输出。我相信我已经找到了数组的来源,我只需要对其进行排序。排序()没有工作。我使用 print_r 查看数组,它的维度超出了我的小脑袋所能处理的范围。如何按完整的货币名称对其进行排序?

Array ( [0] => Array ( [id] => USD [text] => US Dollar ) [1] => Array ( [id] => EUR [text] => Euro ) [2] => Array ( [id] => GBP [text] => United Kingdom Pound ) [3] => Array ( [id] => CAD [text] => Canadian Dollar ) [4] => Array ( [id] => AUD [text] => Australian Dollar ) [5] => Array ( [id] => CHF [text] => Swiss Franc ) [6] => Array ( [id] => CZK [text] => Czech Koruna ) [7] => Array ( [id] => DKK [text] => Danish Krone ) [8] => Array ( [id] => HKD [text] => Hong Kong Dollar ) [9] => Array ( [id] => HUF [text] => Hungarian Forint ) [10] => Array ( [id] => JPY [text] => Japanese Yen ) [11] => Array ( [id] => NZD [text] => New Zealand Dollar ) [12] => Array ( [id] => NOK [text] => Norwegian Kroner ) [13] => Array ( [id] => PLN [text] => Polish Zloty ) [14] => Array ( [id] => SGD [text] => Singapore Dollar ) [15] => Array ( [id] => SEK [text] => Swedish Krona ) [16] => Array ( [id] => ILS [text] => Israeli New Shekel ) [17] => Array ( [id] => MXN [text] => Mexican Peso ) [18] => Array ( [id] => TWD [text] => Taiwan Dollar ) [19] => Array ( [id] => PHP [text] => Philippine Peso ) [20] => Array ( [id] => THB [text] => Thai Baht ) )
4

1 回答 1

2

正如 Interstellar_Coder 所说,使用usort,但要正确使用!

usort($array,create_function('$a,$b','return strnatcasecmp($a["text"],$b["text"]);'));

或者,从 PHP 5.3 开始:

usort($array,function($a,$b) {return strnatcasecmp($a['text'],$b['text']);});
于 2012-06-06T01:40:32.833 回答