This example describes how the PHP array generates an HTML Drop-down list. Share to everyone for your reference. Specifically as follows:
This code can dynamically generate an HTML Drop-down list (select) based on a well-defined PHP array.
<?php
//array Contents Array 1:: Value
$myArray 1 = Array (' Cat ', ' Mat ', ' Fat ', ' Hat ');
Array Contents array 2:: Key => value
$myArray 2 = 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 ($myArray 1 as $word) {
echo ' <option value= '. $w Ord. ' > '. $word. ' </option> ';
}
Echo ' </select> ';
Values from array 2
echo ' <select name= ' Words ' > ';
For each key to the array assign a variable name let
//for each value of the array assign a variable name word
foreach ($myArray 2 as $let => $word) {
echo ' <option value= '. $let. ' " > '. $word. ' </option> ';
}
Echo ' </select> ';
? >
I hope this article will help you with your PHP program design.