Skip to content

Instantly share code, notes, and snippets.

@lukaswhite
Created May 17, 2021 06:35
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 lukaswhite/46adf6d5f05480045e7c9d4b1efaffc5 to your computer and use it in GitHub Desktop.
Save lukaswhite/46adf6d5f05480045e7c9d4b1efaffc5 to your computer and use it in GitHub Desktop.
Nationalities in PHP
(new \PragmaRX\Countries\Package\Countries())
->all()
->keyBy('iso_3166_1_alpha2')
->filter(function ($value, $key) {
return (bool)strlen($key);
})
->pluck('demonyms.eng.m')
->filter(function($name){
return !empty($name);
})
->unique()
->mapWithKeys(function($item){
return [$item => $item];
})
->sort(function($a, $b){
$at = iconv('UTF-8', 'ASCII//TRANSLIT', $a);
$bt = iconv('UTF-8', 'ASCII//TRANSLIT', $b);
return strcmp($at, $bt);
})
@lukaswhite
Copy link
Author

This code pulls out the nationalities from this package and sorts them alphabetically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment