Php array function array_multisort () usage

Source: Internet
Author: User
Php array function array_multisort () usage

  1. $ Arr1 = array ('10', 11,100,100, 'A ');
  2. $ Arr2 = array (1, 2, 3, '2', 5 );
  3. Array_multisort ($ arr1, $ arr2 );
  4. ?>

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 <

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.