# Sorting Arrays
- sort() - Sort Array in Ascending Order
- rsort() - Sort Array in Descending Order
- asort() - Sort Array (Ascending Order), According to Value
- ksort() - Sort Array (Ascending Order), According to Key
- arsort() - Sort Array (Descending Order), According to Value
- krsort() - Sort Array (Descending Order), According to Key
# sort() - Sort Array in Ascending Order
The following example sorts the elements of the $cars array in ascending alphabetical order:
$cars = array("Volvo", "BMW", "Toyota");
sort($cars);
# rsort() - Sort Array in Descending Order
The following example sorts the elements of the $cars array in descending alphabetical order:
$cars = array("Volvo", "BMW", "Toyota");
rsort($cars);
# asort() - Sort Array (Ascending Order), According to Value
The following example sorts an associative array in ascending order, according to the value:
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
asort($age);
# ksort() - Sort Array (Ascending Order), According to Key
The following example sorts an associative array in ascending order, according to the key:
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
ksort($age);
# arsort() - Sort Array (Descending Order), According to Value
The following example sorts an associative array in descending order, according to the value:
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
arsort($age);
# krsort() - Sort Array (Descending Order), According to Key
The following example sorts an associative array in descending order, according to the key:
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
krsort($age);
← Pagination Model →