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
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
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.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.