Array sorting provides a way to organize data sets in either alphabetical order or in numbers, in an ascending or descending manner.
PHP provides inbuilt functions to sort an array. Here are the list.
- sort() – sorts arrays in ascending order
- rsort() – sorts arrays in descending order
- asort() – sorts associative arrays in ascending order, according to the value
- ksort() – sorts associative arrays in ascending order, according to the key
- arsort() – sorts associative arrays in descending order, according to the value
- krsort() – sorts associative arrays in descending order, according to the key
Following is example code to use array sorting function:
<?php
// Define array
$colors = array("Red", "Green", "Blue", "Yellow");
// Sorting and printing array
sort($colors);
print_r($colors);
?>
Output is as following:
Array ( [0] => Blue [1] => Green [2] => Red [3] => Yellow )
Hope it helps.

I like your post . Thanks for posting it. I have learnt something new from this post. For more information i want to try php course in chd.
LikeLike
You put a good post. Thanks for posting it. But can PHP is easy for freshers. Explain it.
LikeLike