Example of sort, asort and ksort usages of PHP array ordering

Source: Internet
Author: User
Tags arrays sort

This paper illustrates the use of sort, asort and ksort in the sequence of PHP arrays for reference. The specific examples are as follows:

01 <?php
02 $arr = Array (' d ' => ' SDF ', ' R ' => ' SDF ', ' a ' => ' eee ');
03 Sort ($arr); Rearrange the values of the array, delete the previous key value, and become an indexed array
04 Asort ($arr); The array is rearrange by value and the index relationship is maintained, and both the indexed and associative arrays apply
05 Ksort ($arr); The array of arrays is queued according to the key value and the index relationship is maintained, and both the indexed and associative arrays apply
06
07 corresponding reverse order and Rsort Arsort Krsort
08 Use a function to compare a usort uksort uasort a function with a comparison that returns a value that is equal to or less than 0 when the first argument is equal to less than the second argument only takes the whole number of points
09
10 Print_r ($arr);
11 ?>

The example of this article is only a demonstration of ksort usage, interested readers can test the results of sort and asort, in order to deepen the impression, firmly grasp. I hope this example will help you with PHP program design.

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.