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 :
- sort() – sorting of arrays in terms of ascending order
- rsort() – sorting of arrays in terms of descending order
- asort() – sorting of associative arrays in terms of ascending order, according to the value
- ksort() – sorting of associative arrays in terms of ascending order, according to the key
- arsort() – sorting of associative arrays in terms of descending order, according to the value
- 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);