Created
August 29, 2013 19:09
-
-
Save pietvanzoen/6382154 to your computer and use it in GitHub Desktop.
Array Values Sorter :: Sort a multi dimensional array by values based on key. #php
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
<?php | |
function array_vals_sorter($array, $val_key, $order = 'asc') { | |
$sorter = array(); | |
foreach ($array as $key => $row) | |
{ | |
$sorter[$key] = $row[$val_key]; | |
} | |
array_multisort($sorter, SORT_ASC, $array); | |
if ($order != 'asc') $array = array_reverse($array,TRUE); | |
return $array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment