Logo
Dropdown Menu From An Array
Online Now: 0
Snippet Code
this snippet will create a drop down menu from an array list.
<?php
//Array contents array 1 :: value
$myArray1 = array('Cat','Mat','Fat','Hat');
//Array contents array 2 :: key => value
$myArray2 = array('c'=>'Cat','m'=>'Mat','f'=>'Fat','h'=>'Hat');

//Values from array 1
echo'<select name="Words">';
//for each value of the array assign a variable name word
foreach($myArray1 as $word){
    echo
'<option value="'.$word.'">'.$word.'</option>';
}
echo
'</select>';

//Values from array 2
echo'<select name="Words">';
//for each key of the array assign a variable name let
//for each value of the array assign a variable name word
foreach($myArray2 as $let=>$word){
    echo
'<option value="'.$let.'">'.$word.'</option>';
}
echo
'</select>';
?>
 
Snippet Comments

Add Your Comment

Supra For Sale
2011-06-15 02:08:10
Latest trend material: At eurohandbag, the main concern is to walk with time. The research department of eurohandbag is totally devoted in finding out what is totally new in the market and accordingly they provide things that are in pace with the current trend. Thus you can have the designer mulberry bags as well as several other bags from eurohandbag.
car ship
2011-05-20 00:03:50
The large numbers of stripe i tried it and had great success, the only problem was finding that color, you would think bass pro.Thanks for sharing the informative post. Regards. Roy.
real estate
2011-02-05 06:22:09
Yes this code snippet looks like it could become very useful for a variety of different purposes. Thanks for the snippet.
Jack
2010-09-13 23:46:10
I believe this is a easy way to build a drodown menu. Thank you very much.
Jack
2010-09-13 23:45:39
I believe this is a easy way to build a drodown menu. Thank you very much.
Garath531
2007-05-23 00:00:00
That was it! Thank you for fixing it.

Garath531
Admin
2007-05-16 00:00:00
I think I found an error, I think it was because double quotes were left out, so I added them in, give it a try now.
Garath531
2007-05-14 00:00:00
This is very good, but there is a slight glitch I can't figure out. It only shows two of the array values. Can you help me?

Add Your Comment

 
Snippet Tools
Rate this Snippet:

Rate the difficulty level:

Request Snippet Update


Suggested Difficulty Level: Beginner
Current Score: 2.81
Total votes: 281
Total Views: 8024

Other top snippets by admin:

1. JPEG to ASCII Converter
2. Add (th, st, nd, rd, th) to the end of a number
3. Dynamic Page Content From Links
4. AJAX Quickie
5. Simple Image CAPTCHA

Search
Search for:







User Panel

User name:

Password:

Register And Post Your Own Snippets

New Snippets

1.  Shorten text and (4 of 1)

2.  file-based simple guest (0 of 0)

3.  adding an entry (0 of 0)

4.  integer to currency (1.33 of 3)

5.  Aggregate IP addresses (0 of 0)

6.  file handling (0 of 0)

7.  testing system with (0 of 0)

8.  Make an php (1 of 1)

9.  allow download in (5 of 1)

10.  redirect in 3 (0 of 0)

11.  live clock with (0 of 0)

12.  visit counter (3.5 of 2)

13.  contact form with (4 of 1)

14.  show a specific (0 of 0)

15.  The & sign (0 of 0)

16.  static variable in (0 of 0)

17.  multiplication table with (0 of 0)

18.  function with multiplicationt (0 of 0)

19.  php generated menu (0 of 0)

20.  drawing a table (0 of 0)

21.  embedded array (one (0 of 0)

22.  checks the week (0 of 0)

23.  put links on (4.5 of 2)

24.  Directory Image Gallery (0 of 0)

25.  TOS (4 of 1)

Home | Forum | Free PHP Web Hosting | Contact | Terms & Conditions |  
Donate
PHPSnips.com - ©2012 Amethyst Creative