php tutorial - PHP Sorting Arrays - php programming - learn php - php code - php script



  • In php the sorting is based on the key and the values of the array.
  • The order of sorting is based on alphabetical, low to high (ascending), high to low (descending), numerical, natural, random, or user defined type.
  • There are different types of sorting functions available in array as shown below :
  1. sort() – sorting of arrays in terms of ascending order
  2. rsort() – sorting of arrays in terms of descending order
  3. asort() – sorting of associative arrays in terms of ascending order, according to the value
  4. ksort() – sorting of associative arrays in terms of ascending order, according to the key
  5. arsort() – sorting of associative arrays in terms of descending order, according to the value
  6. krsort() – sorting of associative arrays in terms of descending order, according to the key

php sort() function :

The sort function is used for defining the array value in ascending order.

Syntax :

sort($variablename);
click below button to copy the code. php tutorial - team

rsort() function :

The rsort function is used for defining the array value in descending order.

php code Syntax :

rsort($variablename);
click below button to copy the code. php tutorial - team

php asort() function :

This sort function is used for associative array and the array values are sorted in ascending order based on the value.

php code Syntax :

asort($variablename);
click below button to copy the code. php tutorial - team

php ksort() function :

This sort function is used for associative array and the array values are sorted in ascending order based on the key.

php code Syntax :

ksort($variablename);
click below button to copy the code. php tutorial - team

php arsort() function :

This sort function is used for associative array and the array values are sorted in descending order based on the value.

php code Syntax :

arsort($variablename);
click below button to copy the code. php tutorial - team

php krsort() function :

This sort function is used for associative array and the array values are sorted in descending order based on the key.

krsort($variablename);
click below button to copy the code. php tutorial - team




Related Searches to php sorting arrays