Werbung
Werbung
Werbung
Archive
Folge uns auf Twitter
Werbung

Jede Menge neue Twitter Follower bekommen. Die Software hat einen kostenlosen Trial Mode, der bis zu 250 Follower bringt.

Willkommen
Willkommen im PHP Archiv Blog! Hier gibts Infos zum Thema PHP Codeschnipsel und Tipps. Bei unserem Projekt phparchiv.de, finden Sie über 5700 Scripte.

Ein Dropdown Menu aus einem Array erstellen

Das kleine Script erzeugt ein Drop Down Menu aus einem Array


//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>';
?>[/php]

Die Idee stammt con phpsnips.com

Hinterlasse eine Antwort

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *

*

Du kannst folgende HTML-Tags benutzen: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>