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
)