Home>Article>Backend Development> PHP array function array_multisort() usage
The result is: $arr1 Array ( [0] => 10 [1] => a [2] => 11 [3] => 100 [4] => 100 ) # '10' is converted to the integer 10 when compared with 11, 100, 100, which is smaller than the other three numbers # '10' is used as a string when compared with 'a'. Its first character '1' has an ascii code value of 49 which is less than 'a' (the ascii value is 97), so '10' is the smallest element. # When 'a' is compared with other three numbers, it is converted to an integer 0, which is less than the other three numbers. $arr2 Array ( [0] => 1 [1] => 5 [2] => 2 [3] => 2 [4] => 3 ) # $arr2 element 1 corresponds to $arr1 element '10' position, so it is ranked at [0] position # $arr1[2] => 100, $arr1[3] => 100 correspond to $arr2 elements 3 and '2' respectively. 3 is greater than '2', so the sorted subscript of $arr1[2] => 100 corresponding to 2 is 3, and the sorted subscript of $arr1[3] => 100 corresponding to 3 is 4 Summary---------- 1. The number of array elements participating in sorting remains consistent. 2. The corresponding positions of the sorted array elements are as follows: ‘10’ => 1, 11 => 2 3. The following arrays are sorted based on the order of the previous arrays. 4. If the previous array encounters equal elements, compare the following array >>> For more information, please view the complete list of php array sorting methods |