Usage notes of PHP array_multisort ()

Source: Internet
Author: User
Tags php source code

Introduction: This is a detailed page of PHP array_multisort () usage notes. It introduces PHP, related knowledge, skills, experience, and some PHP source code.

Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 339823 'rolling = 'no'>?

Function bool array_multisort (array & $ arr [, mixed $ Arg = sort_asc [, mixed $ Arg = sort_regular [, mixed $...])

Parameter description: The function sorts multiple arrays or multi-dimensional arrays.

The first parameter is an array, and each subsequent parameter may be an array or the following sort order mark.

Sort_asc-default, in ascending order

Sort_desc-sort in descending order

You can specify the sorting type.

Sort_regular-default. Sort each item in the general order.

Sort_numeric-Sort each item in numerical order.

Sort_string-Sort each item in alphabetical order.

Instance Code

$ 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, which is smaller than the other three.
# '10' is a string when 'A' is compared. Its first character '1' ASCII code value is 49 less than 'A' (ASCII value is 97 ), therefore, '10' is the minimum element.
# When 'A' is compared with the other three numbers, it is converted to an integer 0, which is smaller than the other three.

$ Arr2
Array ([0] => 1 [1] => 5 [2] => 2 [3] => 2 [4] => 3)
# $ Arr2 element 1 corresponds to $ arr1 element '10', so it is in the [0] position.
# $ Arr1 [2] => 100, $ arr1 [3] => 100 corresponds to $ arr2 element 3, '2' respectively '. 3 is greater than '2'. Therefore, 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. The position of the elements in the sorting array corresponds to, for example, '10' => 1, 11 => 2.
3. The back array is sorted based on the order of the front array.
4. In case of equal elements, the array of the front edge compares the Array

Love J2EE follow Java Michael Jackson video station JSON online tools

Http://biancheng.dnbcw.info/php/339823.html pageno: 7.

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.