PHP:如何排序按字母顺序排列的数组值? [英] PHP: How to sort values of an array in alphabetical order?

查看:145
本文介绍了PHP:如何排序按字母顺序排列的数组值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在PHP中按字母顺序排列数组的值进行排序。如果所有的值开始使用相同的字符,然后将它们放在第二个字符等进行排序。忽略大小写敏感的。

I want to sort values of an array in alphabetical order in PHP. If all values started with same character then they should be sorted using second character and so on. Ignore case sensitive.

例如:

before:
values[0] = "programming";
values[1] = "Stackoverflow";
values[2] = "question";
values[3] = "answers";
values[4] = "AA Systems";

after:
values[0] = "AA Systems";
values[1] = "answers";
values[2] = "programming";
values[3] = "question";
values[4] = "Stackoverflow";

我已经发现了一些算法,但我想要的方式,速度快,有少数语句。忽略大小写是专门为我。谢谢你。

I have found some algorithms but I want a way that is fast and with small number of statements. Ignoring case sensitive is special for me. Thanks.

推荐答案

请参阅

  • natcasesort :<一href="http://www.php.net/manual/en/function.natcasesort.php">http://www.php.net/manual/en/function.natcasesort.php
  • usort :<一href="http://www.php.net/manual/en/function.usort.php">http://www.php.net/manual/en/function.usort.php有一个比较功能比较用strtolower(一)用strtolower(B)
  • natcasesort: http://www.php.net/manual/en/function.natcasesort.php
  • usort: http://www.php.net/manual/en/function.usort.php with a comparator function that compares strtolower(a) and strtolower(b).

这篇关于PHP:如何排序按字母顺序排列的数组值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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