How to insert an item combobox in php

Written by cristina puno
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to insert an item combobox in php
Online registration forms often contain combo boxes. (Comstock/Comstock/Getty Images)

Combo boxes or drop-down menus are a staple in online forms. Combo boxes often show a list of common choices, such as a list of countries or states, to make it easier and faster for users to fill out a form. Using the Web programming language PHP, you can create a combo box with items generated by PHP itself. The use of PHP arrays, let you define items to be placed in a combo box. The same method can also be used to populate a combo box with items from a database.

Skill level:

Other People Are Reading


  1. 1

    Open a new file in Notepad.

  2. 2

    Type in the PHP code to place combo box items in an array:


    $items = array ('apple','banana','orange');


  3. 3

    Add the HTML code for the combo box:

    <select name="select">

    <option value="Choose a fruit" selected>Choose a fruit</option>

  4. 4

    Insert the array items within the combo box using a PHP loop:


    for each ($items as $value) {


    <option value="<?php echo $value; ?>"><?php echo $value; ?></option>





  5. 5

    Save it as a PHP file.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.