Sort a two-dimensional array BY a specified column, similar to ORDERBY in an SQL statement. Sort a two-dimensional array BY a specified column, similar to order by in an SQL statement.
Script ec (2); script
/**
* Sort the Array Based on the specified key value
*
* @ Param array $ array the array to be sorted
* @ Param string $ keyname Key Value Name
* @ Param int $ sortDirection: Sorting direction
*
* @ Return array
*/
Function arraySort ($ array, $ keyname, $ sortDirection = SORT_ASC)
{
Return arrayMultiFields ($ array, array ($ keyname => $ sortDirection ));
}
/**
*
*
* @ Param array $ rowset
* @ Param array $ args
*/
Function arrayMultiFields ($ rowset, $ args)
{
$ SortArray = array ();
$ SortRule = '';
Foreach ($ args as $ sortField => $ sortDir ){
Foreach ($ rowset as $ offset => $ row ){
$ SortArray [$ sortField] [$ offset] = $ row [$ sortField];
}
$ SortRule. = '$ sortArray [''. $ sortField.''],'. $ sortDir .',';
}
If (empty ($ sortArray) | empty ($ sortRule) {return $ rowset ;}
Eval ('array _ multisort ('. $ sortRule.' $ rowset );');
Return $ rowset;
}