Skip to content

Instantly share code, notes, and snippets.


tommcfarlin/using-setlocale.php Secret

Created Mar 13, 2014
What would you like to do?
[WordPress] How to define a new locale for sorting data.
// Set a new locale, define string comparison functions to be affected,
// and store the original locale.
$original_locale = setlocale( LC_COLLATE, 'de_DE' );
// Do whatever you need to do for German sorting here
// Reset the locale to its original state
setlocale( LC_COLLATE, $original_locale );
// Instantiate the Collator and pass it the locale
$col = new \Collator( 'de_DE' );
// Sort the array of last names.
$col->asort( $last_names )
// Done!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment