Sorting an array

Source: Internet
Author: User

PHP has some functions for sorting arrays, and this document lists them.

The main differences are:

      • Some functions are sorted based on the keys of the array, while others are sorted based on values:$array [' key '] = ' value ';.
      • Whether the association between the key and the value can be persisted after sorting means that the key of the array after sorting may be reset to digital type (0,1,2 ... )。
      • The order of sorting is: alphabetical order, from low to High (ascending), from high to low (descending), numeric sort, natural sort, random order or user-defined sort.
      • Note: All of the following sorting functions are directly acting on the array itself, rather than returning a new ordered array.
      • The following functions are not defined in the order in which they are sorted, for elements that are equal in the array. (That is, the order between the equal elements is not stable).

Sort function Properties

Function Name sort on array index key hold Order of sorts related Functions
Array_multisort () Value Retention of key-value associations, non-retention of numeric types The first array is either specified by an option Array_walk ()
Asort () Value Is From low to high Arsort ()
Arsort () Value Is From high to Low Asort ()
Krsort () Key Is From high to Low Ksort ()
Ksort () Key Is From low to high Asort ()
Natcasesort () Value Is Natural sort, case insensitive Natsort ()
Natsort () Value Is Natural sort Natcasesort ()
Rsort () Value Whether From high to Low Sort ()
Shuffle () Value Whether Random Array_rand ()
Sort () Value Whether From high to Low Rsort ()
Uasort () Value Is Defined by user Uksort ()
Uksort () Key Is Defined by user Uasort ()
Usort () Value Whether Defined by user Uasort ()

http://php.net/manual/zh/array.sorting.php

Sorting an array

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.