Skip to content

Instantly share code, notes, and snippets.

@bohman
Created September 12, 2012 07:29
Show Gist options
  • Save bohman/3704955 to your computer and use it in GitHub Desktop.
Save bohman/3704955 to your computer and use it in GitHub Desktop.
sort_array_on_value() - sorting multidimensional arrays into hyperspace
//
// Easy lil' sorting thingamajig. Mad creds to Antonio Navarro of 040.
//
function sort_array_on_value($array_to_sort, $sort_on_value, $descending = false) {
$sortArr = array();
foreach ($array_to_sort as $key => $value) {
$sortArr[$key] = $value[$sort_on_value];
}
if ($descending) {
arsort($sortArr);
} else {
asort($sortArr);
}
$resultArr = array();
foreach ($sortArr as $key => $value) {
$resultArr[$key] = $array_to_sort[$key];
}
return $resultArr;
}
@aholstenson
Copy link

This inspired me to update and share my Sorting-class. It might help you if you need something more advanced.

Check out https://gist.github.com/3705706

@bohman
Copy link
Author

bohman commented Jan 16, 2013

Way cool. Thanks for sharing Andreas!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment