-1

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

1
  • A similar question has already been posed and answered: Sorting an associative array in PHP. Please use the search function next time. See the FAQ. Commented Oct 6, 2011 at 16:31

1 Answer 1

0

Hope this may work.

function cmp($a, $b){
    return $a['id'] - $b['id'];
}
usort($array, 'cmp');
Sign up to request clarification or add additional context in comments.

3 Comments

Why -1 me? This is working actually. T.T
the answer to the question is to link the duplicate and vote for close. Probably because of that.
@hakre oh, sorry I didn't see it :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.