简体   繁体   English

如何使用键从数组中获取价值?

[英]How to get value from an array using the key?

I have an array containing country codes and country names. 我有一个包含国家代码和国家名称的数组。 I need to echo a country from the array. 我需要从数组中回显一个国家。

I have the country code which works as the key of the array: 我有国家代码作为数组的键:

AG

When I do a var_dump 当我做一个var_dump

var_dump($country_list);

I receive the following: 我收到以下信息:

array(224) { [""]=> string(19) "Select a country..." ["AF"]=> string(11) "Afghanistan" ["AL"]=> string(7) "Albania" ["DZ"]=> string(7) "Algeria" ["AD"]=> string(7) "Andorra" ["AO"]=> string(6) "Angola" ["AI"]=> string(8) "Anguilla" ["AQ"]=> string(10) "Antarctica" ["AG"]=> string(19) "Antigua and Barbuda" ["AR"]=> string(9) "Argentina" ["AM"]=> string(7) "Armenia" ["AW"]=> string(5) "Aruba" ["AU"]=> string(9) "Australia" ["AT"]=> string(7) "Austria" ["AZ"]=> string(10) "Azerbaijan" ["BS"]=> string(7) "Bahamas" ["BH"]=> string(7) "Bahrain" ["BD"]=> string(10) "Bangladesh" ["BB"]=> string(8) "Barbados" ["BY"]=> string(7) "Belarus" ["BE"]=> string(7) "Belgium" ["BZ"]=> string(6) "Belize" ["BJ"]=> string(5) "Benin" ....

How can I echo the country name where the country code is: AG 如何回覆国家/地区代码所在的国家/地区名称: AG

It may seem simple to some but I am having difficulties. 对某些人来说,这似乎很简单,但我遇到了困难。

您可以简单地回显它

echo $country_list['AG'];
echo isset($country_list['AG']) ? $country_list['AG'] : '';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM