PHP ksort似乎不受setlocale的影响 [英] PHP ksort seems unaffected by setlocale

查看:63
本文介绍了PHP ksort似乎不受setlocale的影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了一个需要按其键排序的数组(关联数组),并且其中可能包含一些带有重音符号的字符(à,è,ì等).如果有帮助,我确实知道将使用的语言,因此我应该能够在理论上设置语言环境.所以,我最初的理论是这样做:

I've been given an array that needs to be sorted by its key (associative array), and it may have some accented characters in it (à, è, ì, etc.). If it helps any, I do know the language that will be used, so I should be able to set a locale in theory. So, my original theory was to do it like so:

setlocale(LC_COLLATE, 'fre');
ksort($array, SORT_LOCALE_STRING);

这似乎根本不会改变ksort的工作方式-当我认为重音符号至少应排在普通字符之后时,重音字符始终按字母顺序排在最后.例如,èvery"将排在"every"之后,而不是在"fair"之后.因此,然后我开始研究整理程序,但找不到按数组键排序的方法.如果有人有任何想法,将不胜感激.

This doesn't appear to change the way ksort works at all - Accented characters are always last alphabetically when i'd think they should at least come after regular characters. For instance, 'èvery' would come after 'every', but not after 'fair'. So, then I started to look into collator but couldn't find a way to sort by the array keys. If anyone has any ideas it would be greatly appreciated.

推荐答案

这是在Windows还是Linux(或Mac)服务器上?我相信Windows上的语言环境代码略有不同...例如在Linux上为"nl_NL",在Windows上为"nld_nld".

Is this on a Windows or a Linux (or Mac) server? I believe the locale codes are slightly different on Windows... e.g. 'nl_NL' on Linux and 'nld_nld' on Windows.

这篇关于PHP ksort似乎不受setlocale的影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆