What are the different functions in sorting an array?

What are the different functions in sorting an array?

There are six different functions that can be used to sort an array. All of which sort the array in different manners. Some sort based on the array keys, whereas others by the values. It should be noted that all of these functions act directly on the array variable itself, as opposed to returning a new sorted array.

The six functions are as follows:

  • sort() – which sorts arrays in ascending order
  • rsort() – which sorts arrays in descending order
  • asort() – which sorts associative arrays in ascending order, according to the value
  • ksort() – which sorts associative arrays in ascending order, according to the key
  • arsort() – which sorts associative arrays in descending order, according to the value
  • krsort() – which sorts associative arrays in descending order, according to the key

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.