Ad Code



how to sort array in php

Sort PHP Array

There are some predefined php function for array sorting. These function perform different type sorting for the array:-

Function name Sorts by Order of sort Related functions
array_multisort() value first array or sort options array_walk()
asort() value low to high arsort()
arsort() value high to low asort()
krsort() key high to low ksort()
ksort() key low to high asort()
natcasesort() value natural, case insensitive natsort()
natsort() value natural natcasesort()
rsort() value high to low sort()
shuffle() value random array_rand()
sort() value low to high rsort()
uasort() value user defined uksort()
uksort() key user defined uasort()
usort() value user defined uasort()

Examples of these functions:-

1. array_multisort()

    This function used many types and sort indexed array, associative array, and multiple arrays at a time. Normally it sort in ascending order, see the example:-
Array ( [0] => A [1] => B [2] => D [3] => H [4] => Z )

2. asort()

This function sort according to the value of all types array and it is sort in ascending order of array values, see the example:-



Array ( [ramu] => 25 [amit] => 45 [2] => D [dinesh] => 55 [4] => Z )

Post a Comment


  1. Nice and good article.. it is very useful for me to learn and understand easily.. thanks for sharing your valuable information and time.. please keep updating.more 
    php jobs in hyderabad.

  2. Great blog created by you. I read your blog, its best and useful information. You have done a great work. Super blogging and keep it up.php jobs in hyderabad.

  3. Great Explanation and more useful for anyone.Thanks for sharing...
    PHP Training course in chennai

  4. Nice blog has been shared by you. it will be really helpful to many peoples who are all working under the technology.thank you for sharing this blog.
    Digital Marketing Training In India


Ad Code