经测试代码如下:
/**
* 根据定义好的PHP数组动态生成一个html的下拉列表
*
* @param
* @author 编程之家 jb51.cc jb51.cc
**/
//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>';
/*** 来自编程之家 jb51.cc(jb51.cc) ***/