- $ Arr1 = array ('10', 11,100,100, 'A ');
- $ Arr2 = array (1, 2, 3, '2', 5 );
- Array_multisort ($ arr1, $ arr2 );
- ?>
Result: $ arr1 Array ([0] => 10 [1] => a [2] => 11 [3] => 100 [4] => 100) # '10' is converted to an integer 10 when compared with 11,100,100, and smaller than the other three # '10' is used as a string when 'A' is compared, the value of the first character '1' ascii code is 49 less than 'A' (the ascii value is 97 ), so '10' is the smallest element # 'A'. when comparing the other three numbers, it is converted to an integer 0, less than three others $ arr2 Array ([0] => 1 [1] => 5 [2] => 2 [3] => 2 [4] => 3) # $ arr2 element 1 corresponds to $ arr1 element '10', so it is placed in the [0] position # $ arr1 [2] => 100, $ arr1 [3] => 100 corresponds to $ arr2 element 3 and '2' respectively '. 3 is greater than '2', so the subscript corresponding to $ arr1 [2] => 100 after sorting is 3, the subscript of $ arr1 [3] => 100 sorting is 4.
Summary ---------- 1. the number of elements in the array to be sorted must be consistent. 2. for example, '10' => 1, 11 => 2 3. the back array is sorted based on the order of the front edge array 4. in case of equal elements, the array of the front edge compares the array
>>> For more information, see The php array sorting method < |