sort() 用于日语
如果我将当前区域设置设置为日语,我该如何设置才能使日语字符始终比非日语字符具有更高的优先级。例如,现在英文字符将始终出现在片假名字符之前。我怎样才能扭转这种影响?
抱歉不太清楚。如您所见 这里。
最终的结果有Java、NVIDIA和Windows feiiaウォール。 排在日本人物之前位列前三。最后有可能有那些吗?
If I have set my current locale to Japanese, how can I make it so that Japanese characters will always have higher preference than non-Japanese characters. For example, right now English characters will always appear before the Katakana characters. How can I reverse this effect?
Sorry for not being very clear. As you can see here.
The final results have Java, NVIDIA and Windows ファイアウォール.
Ranked as the first three ahead of the Japanese characters. Is it possible to have those at the end?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 usort() 而不是 sort() 这样您就可以按照自己的方式定义比较标准。
尝试这个简单的方法。我已经尝试过 这里,它有效。
因此,对于这个例子,
它返回像
Note: 这只是我对这个问题的快速解决方案,它不是一个完美的解决方案。它基于在比较字符串时检查第一个字节,但您始终可以在其中付出一些努力并改进此函数以根据 Unicode 检查所有多字节字符,然后决定是 $a<=$b 还是 $a>$b。
希望它对你有用!
Use usort() instead of sort() so you can define comparing criteria at your own way.
Try this simple method. I have tried it with example from here, and it works.
So for this example
it returns array like
Note: This is just my quick solution for this problem, and it's not a perfect solution. It's based on checking first byte in comparing strings, but you can always push some effort in it and improve this function to check all multi-byte characters against Unicode and then decide if $a<=$b or $a>$b.
Hope it works for you!
最终,PHP 的
sort()
将其留给底层 libc 来实现排序。正如文章和我的评论所示,并非所有 libc 都以相同的方式排序。如果您需要提供一致的排序规则,那么您将需要使用诸如Collator
它使用第三方库。Ultimately, PHP's
sort()
leaves it to the underlying libc to implement the sort. And as shown in the article and my comment, not all libcs sort the same way. If you need to present a consistent collation then you will need to use something such asCollator
which uses a third-party library instead.