Created
September 17, 2013 15:16
-
-
Save marcogrueter/6595754 to your computer and use it in GitHub Desktop.
sort any array in php with strnatcasecmp
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
// 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