Home > Backend Development > PHP Tutorial > PHP array function array_multisort() usage

PHP array function array_multisort() usage

WBOY
Release: 2016-07-25 09:04:08
Original
1235 people have browsed it
  1. $arr1 = array('10', 11, 100, 100, 'a');
  2. $arr2 = array(1, 2, 3, '2', 5);
  3. array_multisort($arr1, $arr2);
  4. ?>
Copy the code

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



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template