if ($userCount > 0) { foreach ($Country as $country) { $i++; $countryid = $country->getCountryId(); $countryname = $country->getCountryName(); $countrycode = $country->getCountryCode(); $arrayval[$i] = $countryname; echo "The user is: testest" . $countryname . "<br/>"; } // end of foreach loop //$data = json_encode($arrayval); } // end of if statement //For Provinces $provincesbycountryid = $LocationManager->getProvincesByCountryId(1); $getProvincesByCountryName = $LocationManager->getProvincesByCountryName("AfghAnistan"); $citybyCountryid = $LocationManager->getCitiesByCountryId(1); $citybyprovinceid = $LocationManager->getCitiesByProvinceId(1); echo "<br/><br/><br/><b>Provinces by CountryId</b><br>"; $userCount = count($provincesbycountryid); if ($userCount > 0) { foreach ($provincesbycountryid as $provinces) { $provinceid = $provinces->getProvinceId(); $ProvinceName = $provinces->getProvinceName(); $CountryId = $provinces->getCountryId(); ?> <?php echo "The user is: test" . $ProvinceName . "<br>"; ?>