我有这个数组:
server {
server_name .myserver.com
location / {
proxy_pass http://mybackend;
add_header X-Upstream $upstream_addr always;
}
}
我想做 static $countryList = array(
["AF" => "Afghanistan"],
["AL" => "Albania"],
["DZ" => "Algeria"],
//many more countries
);
之类的事情来获得“阿尔及利亚”
为什么那些该死的子阵列?
好吧,有些国家必须来两次 基本上这个......$countryList['DZ']
它用于选择列表
答案 0 :(得分:1)
创建另一个关联数组的数组:
$countryMap = [];
foreach ($countryList as $country) {
foreach ($country as $short => $long) {
$countryMap[$short] = $long;
}
}
然后您可以使用$countryMap["DZ"]