function outputTop10CountryNames($dbAdapter) { $gateVisits = new VisitTableGateway($dbAdapter); $result = $gateVisits->findTop10CountryVisits(); $countryNamesInfoArray = []; foreach ($result as $row) { $countryNamesInfo = new stdClass(); $countryNamesInfo->countryISO = $row->ISO; $countryNamesInfo->countryName = $row->countryName; array_push($countryNamesInfoArray, $countryNamesInfo); } echo json_encode($countryNamesInfoArray); }