S.Faraji S.Faraji - 4 months ago 12
HTML Question

How do I populate a combobox from an array in PHP?

I want to have an simple array in php and a combobox in html.


<?php
// Here is my array:
$cars=array("Volvo","BMW","Toyota");
?>

Answer

Code in php page :

<?php
$cars=array("Volvo","BMW","Toyota");
$smarty->assign('cars', $cars);
?>

Smarty code for HTML page(Template page):

<select name="car">
  {foreach from=$cars item=car}
    <option value="{$car}">{$car}</option>
  {/foreach}
</select>
Comments