I have some languages stored in my database as follows:
id | code | name
--------------------------------------
1 | en_GB | English, United Kingdom
2 | pt_BR | Portugese, Brazil
3 | it_IT | Italian, Italy
4 | hi_IN | Hindi, India
5 | es_BR | Spanish, Brazil
6 | ur_IN | Urdu, India
I want to get these results and sort (or sort after I get all results), so I get the results first by ordered Country Code (second part of code) and then by Locale Code (first part of code) so:
$languages = [
0 => [
'code' => 'es_BR'
],
1 => [
'code' => 'pt_BR'
],
2 => [
'code' => 'en_GB'
],
3 => [
'code' => 'hi_IN'
],
4 => [
'code' => 'ur_IN'
],
5 => [
'code' => 'it_IT'
]
];
I've tried looping through each language and taking out the second part and storing an array of the Country Codes and then sorting them using asort($countryCodes);
, which did sort by Country Code (GB), but I'm stuck sorting that list out by Locale Code (en).
Any help will be appreciated, thanks!