Php arsort array sort in descending order

Source: Internet
Author: User
Tags array sort

Php arsort array sort in descending order

Arsort sorts arrays in descending order and maintains the index relationship.

Basic syntax

Bool arsort (array & $ array [, int $ sort_flags = SORT_REGULAR])

This function sorts the array in descending order. The index of the array remains associated with the unit.

The arsort function is mainly used to sort the arrays that are very important to the unit order.

Parameter introduction:

Parameters Description
Array Required. Input array.
Sort_flags

Optional. Specifies how to arrange the elements/items of an array. Possible values:

  • 0 = SORT_REGULAR-default. Sort each item in the regular order (Standard ASCII, without changing the type)
  • 1 = SORT_NUMERIC-process each item as a number.
  • 2 = SORT_STRING-process each item as a string.
  • 3 = SORT_LOCALE_STRING-process each item as a string based on the current region settings (which can be changed through setlocale ).
  • 4 = SORT_NATURAL-process each item as a string and use natural sorting like natsort.
  • 5 = SORT_FLAG_CASE-you can combine (by bit or) SORT_STRING or SORT_NATURAL to sort strings without case sensitivity.

Description

The arsort () function sorts arrays in reverse order and maintains the index relationship. It is mainly used to sort the arrays that are very important to the unit order.

The second optional parameter contains an additional sorting identifier.

Return Value

Returns TRUE if the call succeeds, or FALSE if the call fails.

Instance:

<?php$fruits = array( "d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple");arsort($fruits);foreach ($fruits as $key => $val) { echo " $key = $val <br/>";}?>  

Running result:

A = orange
D = lemon
B = banana
C = apple

Thank you for reading this article. I hope it will help you. Thank you for your support for this site!

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.