How to generate html drop-down list from php array, php array html drop-down_PHP tutorial

WBOY
Release: 2016-07-13 09:46:03
Original
903 people have browsed it

How to generate html drop-down list from php array, php array html drop-down list

This article describes the method of generating html drop-down list from php array. Share it with everyone for your reference. The details are as follows:

This code can dynamically generate an html drop-down list (select) based on the defined php array

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

Copy after login

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1035664.htmlTechArticleHow to generate html drop-down list from php array, php array html drop-down list. This article describes how to generate html drop-down list from php array. method. Share it with everyone for your reference. The details are as follows: This paragraph...
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!