Home >Backend Development >PHP Tutorial >求写php英文排序

求写php英文排序

WBOY
WBOYOriginal
2016-06-23 14:10:10869browse

如:
a
acb
abc
aca
aaaa


能排成:
a,aaaa,abc,aca,acb
也就是说a排前面,z是最后,第一个字母从a-z,第二个第三个都无限从a-z的顺序排列.


回复讨论(解决方案)

这个需求比较另类

$a = array(  'a',  'acb',  'abc',  'aca',  'aaaa',);$m = max(array_map('strlen', $a));foreach($a as $v) {  $c = substr($v, -1);  $t[] = str_pad($v, $m, $c);}array_multisort($t, $a);print_r($a);
Array
(
    [0] => a
    [1] => aaaa
    [2] => abc
    [3] => aca
    [4] => acb
)

这个需求比较另类

$a = array(  'a',  'acb',  'abc',  'aca',  'aaaa',);$m = max(array_map('strlen', $a));foreach($a as $v) {  $c = substr($v, -1);  $t[] = str_pad($v, $m, $c);}array_multisort($t, $a);print_r($a);
Array
(
    [0] => a
    [1] => aaaa
    [2] => abc
    [3] => aca
    [4] => acb
)

为什么不可以直接用sort排?

系统函数就可以啊

$arr = array(
'a',
'acb',
'abc',
'aca',
'aaaa'
);
sort($arr);

print_r($arr);

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:如何在c++中内嵌php代码Next article:怎么 学习 php