- htmlentities: documentation ( source)
- trim: documentation ( source)
- printf: documentation ( source)
<?php
$result = [
['country_code' => 'US', 'country_name' => 'United States'],
['country_code' => 'UK', 'country_name' => 'United Kingdom'],
];
foreach ($result as $row) {
printf(
"<option value=\"%s\">%s</option>\n",
trim(htmlentities($row['country_code'])),
trim(htmlentities($row['country_name']))
);
}