Http://www6.webng.com/seaboat/article.asp? Id = 660
<? PHP
/**
*
* Two-dimensional arrays are sorted by specified columns.
* @ Param $ arr_data original array
* @ Param $ field specifies the column
* @ Param $ descending: whether to downgrade (the default value is ascending)
* @ Return Array
**/
Function array_sort_by_field ($ arr_data, $ field, $ descending = false)
{
$ Arrsort = array ();
Foreach ($ arr_data as $ key => $ value ){
$ Arrsort [$ key] = $ value [$ field];
}
If ($ descending ){
Arsort ($ arrsort );
} Else {
Asort ($ arrsort );
}
$ Resultarr = array ();
Foreach ($ arrsort as $ key => $ value ){
$ Resultarr [$ key] = $ arr_data [$ key];
}
Return $ resultarr;
}
// Test:
$ Arr = array (
Array ('s' => 'aaa', 'I' => 3 ),
Array ('s' => 'bbb ',' I '=> 2 ),
Array ('s' => 'ccc ',' I '=> 4 ),
Array ('s' => 'ddd ',' I '=> 1 ),
);
Print_r (array_sort_by_field ($ arr, 'I '));
Print_r (array_sort_by_field ($ arr, 'I', true ));
?>