我有一个 MySql 表,它存储来自州和城市列表的用户州和城市。我专门将每个州编码为两个字母的缩写版本(如华盛顿的 WA 和加利福尼亚的 CA),每个城市都有两个字母的缩写,城市名称的格式如下:科罗拉多州博尔德CO-boulder
和犹他州盐湖城UT-salt-lake-city
避免使用相同城市名称的不同州。UT-salt-lake-city
PHP在列下插入值( ) City
,但是当我通过PHP调用变量时,它显示如下:Your location is: UT-salt-lake-city, Utah.
为了解决这个问题,我一直在制作这个变量列表
if ($city == "AL-auburn") { $city = "Auburn"; }
else if ($city == "AL-birmingham") { $city = "Birmingham"; }
else if ($city == "GA-columbus") { $city = "Columbus"; $state = "Georgia"; }
else if ($city == "AL-dothan") { $city = "Dothan"; }
else if ($city == "AL-florence") { $city = "Forence"; }
else if ($city == "AL-muscle-shoals") { $city = "Muscle Shoals"; }
else if ($city == "AL-gadsden-anniston") { $city = "Gadsden Anniston"; }
else if ($city == "AL-huntsville") { $city = "Huntsville"; }
else if ($city == "AL-decatur") { $city = "Decatur"; }
else if ($city == "AL-mobile") { $city = "Mobile"; }
else if ($city == "AL-montgomery") { $city = "Montgomery"; }
else if ($city == "AL-tuscaloosa") { $city = "Tuscaloosa"; }
有没有办法可以缩短这个过程,或者至少从一个单独的文件中调用它,这样我就不必每次想调用该位置时都复制/粘贴?