diff options
author | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-07-07 16:30:35 +0000 |
---|---|---|
committer | brettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-07-07 16:30:35 +0000 |
commit | 9eb97459679cd248804933cdf6d50d48ac19e7ed (patch) | |
tree | 21f7e5c8577a40e911ef20671bdc7483931da3d1 /engine/lib | |
parent | 0950d3f789524017f60849565dd502c7a289f522 (diff) | |
download | elgg-9eb97459679cd248804933cdf6d50d48ac19e7ed.tar.gz elgg-9eb97459679cd248804933cdf6d50d48ac19e7ed.tar.bz2 |
Added elgg_sort_3d_array_by_value(). I do this often enough that a helper function will be nice.
git-svn-id: http://code.elgg.org/elgg/trunk@6657 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib')
-rw-r--r-- | engine/lib/elgglib.php | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 385660d01..f41c87a7d 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -2411,6 +2411,37 @@ function elgg_get_array_value($key, array $array, $default = NULL) { } /** + * Sorts a 3d array by specific element. + * Will re-index numeric indexes. + * NB: This operates the same as the built-in sort functions. + * ie, sorts the array and returns a bool for success. + * + * Do this: elgg_sort_3d_array_by_value($my_array); + * Not this: $my_array = elgg_sort_3d_array_by_value($my_array); + * + * @param array $array Array to sort + * @param string $element Element to sort by + * @param $sort_order + * @param $sort_type + * @return bool + */ +function elgg_sort_3d_array_by_value(&$array, $element, $sort_order = SORT_ASC, $sort_type = SORT_LOCALE_STRING) { + $sort = array(); + + foreach ($array as $k => $v) { + if (isset($v[$element])) { + $sort[] = strtolower($v[$element]); + } else { + $sort[] = NULL; + } + } + + var_dump($sort, $array); + + return array_multisort($sort, $sort_order, $sort_type, $array); +} + +/** * Some useful constant definitions */ define('ACCESS_DEFAULT', -1); |