From 6b8f1136183518cd02925e636522c186687450a7 Mon Sep 17 00:00:00 2001 From: Tarik Manoar Date: Tue, 16 Apr 2024 09:05:30 +0600 Subject: [PATCH] Sort countries by name in ascending order --- src/CountryLoader.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/CountryLoader.php b/src/CountryLoader.php index 115e43d..e6493d6 100644 --- a/src/CountryLoader.php +++ b/src/CountryLoader.php @@ -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];