PHP array sorting-sort, asort, and ksort usage example

Source: Internet
Author: User
This article mainly introduces the sort, asort, and ksort usage of PHP array sorting. The example briefly demonstrates the usage of sort, asort, and ksort, and provides annotations to describe them in detail, for more information about how to use sort, asort, and ksort in PHP array sorting. The specific example is as follows:

<? Php $ arr = array ('D' => 'sdf ', 'R' => 'sdf', 'a' => 'Eee '); // sort ($ arr); // sorts the values of the array, deletes the previous key value, and changes it to the index array // asort ($ arr ); // sorts the array by value and maintains the index relationship. ksort ($ arr) applies to the index array and associated array; // sorts the array by key value, and maintain the index relationship, both the index array and the associated array are applicable // The corresponding reverse order and rsort arsort krsort // compare the usort uksort uasort. The second parameter is the comparison function. The first parameter must be equal to or greater than the second parameter. return a floating point number equal to or greater than 0. only the integer part print_r ($ arr);?>

The examples in this article only demonstrate the usage of ksort. if you are interested, you can test the running results of sort and asort to gain a better understanding of them. I hope this example will help you with PHP programming.

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.