Problems with sorting arrays

Source: Internet
Author: User
sorting problems with arrays!
$a =array (' Zhang San ' and ' Bai '), ' John Doe ' and ' the ' hundred and nine ', ' Harry ' and ' Qi Bai ', ' sun six ' = ' ba ', ' Chen Qi ' and ' "RMB '".

The array is sorted by the number size represented by the man, without changing the index, and the result of the final output should be the following format:

Array (' john doe ' = ' one Bai ', ' Zhang San ' and ' Bai ') ', ' Harry ' and ' Qi Bai ', ' Sun Six ' and ' ba ', ' Chen Qi ' and ' RMB ' "

Code as simple as possible I'm a novice, and the last sort with array sort function
------Solution--------------------
 $a = Array (
' zhang san ' = ' and ' Bai ') ',
' John Doe ' and ' one Bai Jiu ',
' harry ' = ' Qi bai ',
' sun six ' = ' Ba ',
' Chen Qi ' and ' RMB II '
);

$t = Array_map (' Cton ', $a);
Array_multisort ($t, $a);
Print_r ($a);

Function Cton ($s) {
$dw = array (' pick ' up ' = 10 ', ' bai ' + = 100, ' thousand ' = 1000, ' million ' = 10000);
$digital = Array (' 0 ' = + 0, ' one ' = 1, ' II ' and ' 2 ', ' three ' = 3, ' ' ', ' = ' 4, '
' ' and ' 5 ', ' land ' = > 6, ' Qi ' and 7, ' BA ' and 8, ' JIU ' and 9 ';
$ar = Preg_split ('/(') Join ('
------solution--------------------
', Array_keys ($DW)). ')/',
$s,-0, Preg_split_no_empty
------Solution--------------------
Preg_split_delim_capture); br> for ($i =0; $i $res [] = $digital [$ar [$i]] * (Isset ($ar [$i +1]) * $DW [$ar [$i +1]]: 1); br>}
Return Array_sum ($res);
}
Array
(
[John Doe] = a bai jiu pick
[Zhang San]
[Harry] = Qi Bai
[Sun six] = Ba
[Chen Qi] = restaurant RMB bai
)

  • 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.