Skip to content

Instantly share code, notes, and snippets.

@DASPRiD
Created October 10, 2017 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DASPRiD/cd5c361f34c2828282a7025d96cfe7b9 to your computer and use it in GitHub Desktop.
Save DASPRiD/cd5c361f34c2828282a7025d96cfe7b9 to your computer and use it in GitHub Desktop.
public static function getCountryOptions(string $locale) : array
{
$resourceBundle = ResourceBundle::create($locale, 'ICUDATA-region');
$options = [];
foreach ($resourceBundle['Countries'] as $countryCode => $label) {
if (!preg_match('(^[A-Z]{2}$)', $countryCode) || 'ZZ' === $countryCode) {
continue;
}
$options[$countryCode] = $label;
}
$collator = new Collator($locale);
$collator->asort($options);
return $options;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment