How to pull out the value of 'country' and 'city'

array ( 'city' => array ( 'id' => 703448, 'lat' => 50.454659999999997, 'lon' => 30.523800000000001, 'name_ru' => 'Киев', 'name_en' => 'Kiev', ), 'region' => array ( 'id' => 703447, 'name_ru' => 'Киев', 'name_en' => 'Kyiv', 'iso' => 'UA-30', ), 'country' => array ( 'id' => 222, 'iso' => 'UA', 'lat' => 49, 'lon' => 32, 'name_ru' => 'Украина', 'name_en' => 'Ukraine', ), ) 

  • 3
    $array['country'] $array['city'] ? Oo - Moonvvell
  • Notice: Undefined variable: array in geo / index.php on line 26 - Andrei
  • ini_set ("display_errors", 1); error_reporting (E_ALL); include ("SxGeo.php"); $ ip = $ _SERVER ['REMOTE_ADDR']; $ SxGeo = new SxGeo ('SxGeoCity.dat'); var_export ($ SxGeo-> getCityFull ($ ip)); echo $ array ['country']; echo $ array ['city']; - Andrei
  • 2
    Well, substitute your array name. In general, it is better to read about working with arrays in php. - Moonvvell
  • omg, take you finally some book on PCP read. not the first question you ask, which is more elementary than you can imagine. - teran

1 answer 1

 $ip = $_SERVER['REMOTE_ADDR']; $SxGeo = new SxGeo('SxGeoCity.dat'); $city = $SxGeo->getCityFull($ip); var_dump($city['country']); var_dump($city['city']); 

And a lot of advice to read about working with data types, in particular with arrays.

  • Thank! Error displays Notice: Array to string conversion in geo / index.php on line 17 - Andrew
  • @Andrey, what is not clear to you in this notification? - Visman
  • @ Andrew, I unfortunately do not know what you have in line 17. See in your code what is going on in this place. - Moonvvell
  • 17 line echo $ city ['country']; 18 line echo $ city ['city']; - Andrei
  • heh replace echo with var_dump if you need output or delete these lines altogether. In $city['country'] is information about the country. Therefore, you can work with this variable. - Moonvvell