Question : how to populate dropdown list with array values in php
Answered by : ivan-londono
<select name="mydropdown"> <option selected="selected">Choose one</option> <?php // A sample product array $products = array("Mobile", "Laptop", "Tablet", "Camera"); // Iterating through the product array foreach($products as $item){ echo "<option value='strtolower($item)'>$item</option>"; } ?>
</select>
Source : | Last Update : Thu, 20 May 21
Question : php populate select from array
Answered by : martin-de-jonge
$array = array( 1=>"My first option", 2=> "My second option"
);
<select> <?php foreach($array as $key => $value) { ?> <option value="<?php echo $key ?>"><?php echo $value ?></option> <?php }?>
</select>
Source : https://stackoverflow.com/questions/5249825/auto-populate-a-select-box-using-an-array-in-php | Last Update : Sat, 12 Mar 22