用php中的特殊字符对多维数组进行排序 [英] Sort multidimensional array with special characters in php
本文介绍了用php中的特殊字符对多维数组进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个多维数组,按字母顺序排序,但是问题是丹麦特殊字符æøå.它们应按该顺序排序,但不按该顺序返回.
I have a multidimensional array, that I'm sorting alphabetically, but problem is, with danish special characters æ ø å. They should be sorted in that order, but is not returned in that order.
这是我的数组(部分数组已删除)
This is my array (part of is removed)
Array
(
[0] => Array
(
[Name] => John
)
[1] => Array
(
[Name] => Pater
)
[2] => Array
(
[Name] => Allan
)
[3] => Array
(
[Name] => Ø test
)
[4] => Array
(
[Name] => Å test
)
[5] => Array
(
[Name] => Æ test
)
)
我正在使用此功能对其进行排序
I'm using this function to sort it
uasort($sorted_region, function($a, $b) {
$retval = $a['Name'] <=> $b['Name'];
return $retval;
});
任何人都知道,如何对它进行排序,所以我以正确的顺序得到æøå?
Anyone know, how to sort it, so I get æ ø å in the right order?
例如,我已经看到一些使用
I've seen some using e.g.
setlocale(LC_COLLATE, 'da_DK.utf8');
asort($array, SORT_LOCALE_STRING);
但是我不确定如何在多维数组中实现它.
But I'm not sure how to implement this in a multidimensional array.
感谢您的帮助! :-)
Thanks for any help! :-)
推荐答案
实际上这似乎可行
setlocale(LC_ALL, 'da_DK.utf8');
usort($sorted_region, function($a, $b) {
return strcoll($a['Name'], $b['Name']);
});
这篇关于用php中的特殊字符对多维数组进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文