给我带有子阵列的多维php数组的价值

时间:2017-11-03 20:45:50

标签: php arrays

我有这个数组:

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']

它用于选择列表

1 个答案:

答案 0 :(得分:1)

创建另一个关联数组的数组:

$countryMap = [];
foreach ($countryList as $country) {
    foreach ($country as $short => $long) {
        $countryMap[$short] = $long;
    }
}

然后您可以使用$countryMap["DZ"]