Skip to content

Commit

Permalink
Sort countries by name in ascending order
Browse files Browse the repository at this point in the history
  • Loading branch information
tarikmanoar committed Apr 16, 2024
1 parent 0fdccd0 commit 6b8f113
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/CountryLoader.php
Expand Up @@ -54,6 +54,11 @@ public static function countries($longlist = false, $hydrate = false)
static::$countries[$list] = json_decode(static::getFile(__DIR__.'/../resources/data/'.$list.'.json'), true);
}

// Sort countries by name in ascending order
usort(static::$countries[$list], function ($a, $b) {
return strcmp($a['name'], $b['name']);
});

return $hydrate ? array_map(function ($country) {
return new Country($country);
}, static::$countries[$list]) : static::$countries[$list];
Expand Down

0 comments on commit 6b8f113

Please sign in to comment.