I know how to get country codes by using Country Name (english) but my task needed to get the country code using a country name that is translated in Japanese text. Example for Indonesia:
Country : インドネシア Code : ID
Right now, I made an array list of countries (in jp) with the code but it's too manual and needed to add the all other countries possible. I am thinking if there are still other way to do it.
private function getCountryCode($countryName)
{
$list = [
['value' => 'インドネシア', 'code' => 'ID'],
['value' => 'カンボジア', 'code' => 'KH'],
['value' => 'ベトナム', 'code' => 'VN'],
['value' => 'アフガニスタン', 'code' => 'AF']
];
if($countryName){
foreach($list as $l){
if($l['value'] == $countryName){
return $l['code'];
}
}
return '';
}
}