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

求写php英文排序

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-23 14:10:10
Original
907 people have browsed it

如:
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);
Copy after login
Copy after login
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);
Copy after login
Copy after login
Array
(
    [0] => a
    [1] => aaaa
    [2] => abc
    [3] => aca
    [4] => acb
)

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

系统函数就可以啊

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

print_r($arr);

Related labels:
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template