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", 开发者_Python百科i'm expecting this result:
$array = array( 0 => array("id"=>15), 1 => array("id"=>19) , 2 => array("id"=>25) );
Anybody can help ?
Thanks
Hope this may work.
function cmp($a, $b){
return $a['id'] - $b['id'];
}
usort($array, 'cmp');
精彩评论