Closed (fixed)
Project:
GeoNames
Version:
6.x-1.1
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
25 Feb 2009 at 04:01 UTC
Updated:
25 Feb 2009 at 08:50 UTC
Greetings!
Given this query:
<?php
$me = array()
$query = array('lat' => 59.95, 'lng' => 10.77);
$result = geonames_query('countrycode', $query);
foreach ($result->results as $place) {
$me[] = $place[countryname];
}
?>
How do I ensure that this snippet does not return an empty result set? When no result, foreach gives warnings saying array does not exist. In this case that happens over oceans and international land where there is no country.
Tried using if (!empty($result->results)){foreach_query} else {$me = "international"};, though it did not work.
Thanks for all feedback! :)
Comments
Comment #1
2xe commentedjust add a test;