从PHP中检索数组值

I have this function:

print_r(geoip_record_by_name('php.net'));

This results in:

Array ( 
   [continent_code] => NA 
   [country_code] => US
   [country_code3] => USA 
   [country_name] => United States 
   [region] => CA [city] => Sunnyvale 
   [postal_code] => 94089 
   [latitude] => 37.424900054932 
   [longitude] => -122.0074005127 
   [dma_code] => 807
   [area_code] => 408 
)

I want to retrieve the region value, but

geoip_record_by_name('php.net')['region'];

gives a blank result.

$arrayName = geoip_record_by_name('php.net');
echo $arrayName['region'];

You can only used the syntax you used in PHP 5.4

You can't do that in PHP (< 5.4). You need to save the array as a variable first.

$geoip = geoip_record_by_name('php.net');
echo $geoip['region'];

Array docs: http://php.net/manual/en/language.types.array.php#language.types.array.syntax.accessing

The following syntax is only supported in PHP >= 5.4:

geoip_record_by_name('php.net')['region'];

If you are using some other version, you will have to do:

$arr = geoip_record_by_name('php.net');
echo $arr['region'];

Docs: