php数组生成html下拉列表的方法_php技巧
May 16, 2016 pm 08:10 PM
html
php
drop-down list
array
本文实例讲述了php数组生成html下拉列表的方法。分享给大家供大家参考。具体如下:
这段代码可根据定义好的php数组动态生成一个html的下拉列表(select)
<?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>'; ?>
Copy after login
希望本文所述对大家的php程序设计有所帮助。
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian
