Skip to content

Instantly share code, notes, and snippets.

@DWboutin
Created February 11, 2013 20:52
Show Gist options
  • Save DWboutin/4757512 to your computer and use it in GitHub Desktop.
Save DWboutin/4757512 to your computer and use it in GitHub Desktop.
Sort by specific key
function subval_sort($a,$subkey) {
foreach($a as $k=>$v) {
$b[$k] = strtolower($v[$subkey]);
}
asort($b);
foreach($b as $key=>$val) {
$c[] = $a[$key];
}
return array_reverse($c);
}
// usage
subval_sort($myArray, 'theKey');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment