Several array sorting methods in PHP

Source: Internet
Author: User

Introduction: This is a detailed page of several array sorting methods in PHP. It introduces PHP, related knowledge, skills, experience, and some PHP source code.

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

1. Simple array sorting (the key names of the original array will be ignored)

Sort ($ ARR) rsort ($ ARR)

2. Sort the array by key name

Ksort ($ ARR) krsort ($ ARR)

3. Sort the Array Based on the element value (Reserve key => value relationship)

Asort ($ ARR) arsort ($ ARR)

4. Natural Number sorting method

Natsort ($ ARR) // sorts the natural numbers that ignore case sensitivity. natcasesort ($ ARR)

5. Examples of using the usort () method (custom sorting method)

$ Lamp = array ("Linux", "Apache", "MySQL", "php"); usort ($ lamp, "sortbylen"); function sortbylen ($ one, $ two) {If (strlen ($ one) = strlen ($ Two) return 0; elsereturn (strlen ($ one) <strlen ($ Two ))? 1:-1;} print_r ($ lamp); echo '<br> ';

More articles on how to sort arrays in PHP

Love J2EE follow Java Michael Jackson video station JSON online tools

Http://biancheng.dnbcw.info/php/336874.html pageno: 9.

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.