Skip to content

How to populate dropdown list with array values in PHP?

<select name="mydropdown">
        <option selected="selected">Choose one</option>
        // 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>";
See also  Java code snippet - How to calculate the amount of months between two dates ?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.