-2

Possible Duplicate:
Sorting an associative array in PHP
How to sort a multidimensional array by a certain key?

I would like to know how can I sort an array in array by a specific key.

For example:

$array = array( 0 => array("id"=>25), 1 => array("id"=>15) , 2 => array("id"=>19) );

now I want to sort the array by the key "id", i'm expecting this result:

$array = array( 0 => array("id"=>15), 1 => array("id"=>19) , 2 => array("id"=>25) );

Anybody can help ?

Thanks

Community
  • 1
  • 1
Arfeen
  • 2,455
  • 2
  • 26
  • 47
  • A similar question has already been posed and answered: [Sorting an associative array in PHP](http://stackoverflow.com/questions/777597/sorting-an-associative-array-in-php). Please use the search function next time. See the [FAQ](http://stackoverflow.com/faq). – hakre Oct 06 '11 at 16:31

1 Answers1

0

Hope this may work.

function cmp($a, $b){
    return $a['id'] - $b['id'];
}
usort($array, 'cmp');
Rufus
  • 3,645
  • 2
  • 20
  • 28