Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save reginaldojunior/57d7905566ad0c3685d2d47d68c3ba84 to your computer and use it in GitHub Desktop.
Save reginaldojunior/57d7905566ad0c3685d2d47d68c3ba84 to your computer and use it in GitHub Desktop.
function array_sort_bycolumn(&$array, $column, $dir = 'asc') {
$newarr = null;
$sortcol = array();
foreach ($array as $a) {
$sortcol[$a[$column]][] = $a;
};
ksort($sortcol);
foreach ($sortcol as $col) {
foreach ($col as $row)
$newarr[] = $row;
}
if ($dir == 'desc')
if ($newarr) {
$array = array_reverse($newarr);
} else {
$array = $newarr;
} else
$array = $newarr;
return $array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment