How to create a dropdown from array in PHP

To create a dropdown from array in PHP you can use the following snippet.

Sample PHP

$testArray = array('Sample1','Sample2','Sample3','Sample4');
echo'<select name="Items">'; 
foreach($testArray as $item){ 
    echo'<option value="'.$item.'">'.$item.'</option>'; 
} 
echo'</select>'; 

2 thoughts on “How to create a dropdown from array in PHP

Leave a Reply