PHP Code Snippets Episode 2

laptop with code

In this post I am going to show you how to take the values from an array and use them, in a form option box. First of all we are going to make a simple array…

For this example i will just make a basic array, however you could use a<em> mysql_fetch_array()</em> to read data from a database to make your array then continue with step 2.

I will show you the basics of this in my next tut.

<pre class=”syntax”><!–?php $options = array(“option_1″,”option_2″,”option_3″,”option_4″,”option_5″,”option_6″); ?–>


<form><select name=”example”><!–?php foreach($options as $choice) { echo ‘&lt;option value=”‘.$choice.'”&gt;’.$choice.’&amp;lt;/option&gt;’; } ?–></select></form>

As you can see this will give you all the options from the array into your option choices.

I hope this little snippet will help.

DSM Design LTD - Brand Logo

Get in Contact with DSM Design

If you require development services get in touch with DSM Design today. Either use our online form or call us on 01202 048079.

Contact Us

Latest News

View All Articles