Skip to content

Instantly share code, notes, and snippets.

@marcogrueter
Created September 17, 2013 15:16
Show Gist options
  • Save marcogrueter/6595754 to your computer and use it in GitHub Desktop.
Save marcogrueter/6595754 to your computer and use it in GitHub Desktop.
sort any array in php with strnatcasecmp
// just make sure the $sort_by key exists in $data
public function sort_entries(&$data, $sort_by = false)
{
if( ! $sort_by )
{
$sort_by = 'sort';
}
usort($data, function($a, $b) use($sort_by) {
return strnatcasecmp($a[$sort_by], $b[$sort_by]);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment