Heim  >  Artikel  >  Backend-Entwicklung  >  php数组生成html下拉列表的方法,php数组html下拉_PHP教程

php数组生成html下拉列表的方法,php数组html下拉_PHP教程

WBOY
WBOYOriginal
2016-07-13 09:46:03896Durchsuche

php数组生成html下拉列表的方法,php数组html下拉

本文实例讲述了php数组生成html下拉列表的方法。分享给大家供大家参考。具体如下:

这段代码可根据定义好的php数组动态生成一个html的下拉列表(select)

<&#63;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>'; 
&#63;>

希望本文所述对大家的php程序设计有所帮助。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1035664.htmlTechArticlephp数组生成html下拉列表的方法,php数组html下拉 本文实例讲述了php数组生成html下拉列表的方法。分享给大家供大家参考。具体如下: 这段...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn