Current Location: Home> Function Categories> arsort

arsort

Reversely sort the array and maintain index relationships
Name:arsort
Category:Array
Programming Language:php
One-line Description:Sort the associative arrays in descending order by key values.

Definition and usage

arsort() function sorts the associative arrays in descending order by key values.

Tip: Please use the asort() function to sort the associative arrays in ascending order by key values.

Tip: Please use the krsort() function to sort the associative arrays in descending order by key names.

Example

Sort the associative arrays in descending order by key values:

 <?php
$age = array ( "Bill" => "60" , "Steve" => "56" , "Mark" => "31" ) ;
arsort ( $age ) ;
?>

Try it yourself

grammar

 arsort ( array , sortingtype ) ;
parameter describe
array Required. Specifies the array to be sorted.
sortingtype

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

  • 0 = SORT_REGULAR - Default. Arrange each item in a regular order (Standard ASCII, without changing the type)
  • 1 = SORT_NUMERIC - Treat each item as a number.
  • 2 = SORT_STRING - Handle each item as a string.
  • 3 = SORT_LOCALE_STRING - Handle each item as a string, based on the current locale setting (can be changed via setlocale()).
  • 4 = SORT_NATURAL - Handle each item as a string, using a natural sort like natsort().
  • 5 = SORT_FLAG_CASE - Strings can be sorted in combination with (bit-by-bit or) SORT_STRING or SORT_NATURAL, case-insensitive.

illustrate

arsort() function reverses the array and maintains the index relationship. It is mainly used to sort those combined arrays whose unit order is important.

The optional second parameter contains the additional sorting identifier.

Return TRUE if successful, otherwise return FALSE.

Similar Functions
Popular Articles