Created
June 17, 2016 15:04
-
-
Save reginaldojunior/57d7905566ad0c3685d2d47d68c3ba84 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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