PHP arsort() function

PHP arsort() function

The arsort() function in PHP sorts an array in the reverse order and maintains the index association

Syntax

Parameter

array(required)– This parameter represents the input array.

sort_flags (optional)– This parameter is used to modify the behavior of the sort. The various possible values for sorting type flags are as follows:

  • SORT_REGULAR – It is used to compare items normally (don’t change types)
  • SORT_NUMERIC – This flag is used to compare the items numerically.
  • SORT_STRING – It compares the given items as strings.
  • SORT_LOCALE_STRING – This flag compares the items as strings, based on the current locale.
  • SORT_NATURAL – It is used to compare items as strings using “natural ordering” like natsort().
  • SORT_FLAG_CASE – It can be combined (bitwise OR) with SORT_STRING or SORT_NATURAL to sort the given strings case-insensitively

Return

This function returns a Boolean value TRUE on success or FALSE on failure.

Example 1

Output

Example 2

Output

Example 3

Output

Example 4

Output