For example, to sort php in English:
A
Acb
Abc
Aca
Aaaa
Line:
A, aaaa, abc, aca, acb
That is to say, in front of a, z is the last. The first letter is arranged infinitely from a-z, and the second and third are arranged in the order of a-z.
Reply to discussion (solution)
This requirement is quite different.
$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] =>
[1] => aaaa
[2] => abc
[3] => aca
[4] => acb
)
This requirement is quite different.
$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] =>
[1] => aaaa
[2] => abc
[3] => aca
[4] => acb
)
Why can't I use sort directly?
System functions.
$ Arr = array (
'A ',
'Acb ',
'ABC ',
'Aca ',
'AAA'
);
Sort ($ arr );
Print_r ($ arr );