You could alternatively do it just by building the expected output: (Untested)
<?php
$countries = '';
foreach ($objDays->days as $days) {
if($days->dateMatch == "Yes" && !empty($days->locales)) {
foreach(explode(',', $days->locales) as $text){
$countries .= "
<img src='images/icons/flags-32/flag_".str_replace(" ", "_", $text).".png'
alt='".htmlentities($days->desc)."'
id='c".htmlentities($text)."'
style='width:32px' /> " . htmlentities($days->desc);
}
}
}
if(empty($countries)){
echo " <img src='images/icons/emotion_what.png' alt='' /> No data on file for this date.";
}else{
echo $countries;
}
?>