Write php in English

Source: Internet
Author: User
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 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.