PHP asort() function

PHP asort() function

The asort() function in PHP is used to sort an array while maintaining the index association.

Syntax

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

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