Created
May 17, 2021 06:35
-
-
Save lukaswhite/46adf6d5f05480045e7c9d4b1efaffc5 to your computer and use it in GitHub Desktop.
Nationalities in PHP
This file contains hidden or 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
(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); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code pulls out the nationalities from this package and sorts them alphabetically.