Exercises One:
Set array
$attr = Array (
Array ("n001", "Han"),
Array ("n002", "Hui"),
Array ("n003", "Miao"),
Array ("n004", "Uighur"),
);
1. Require a drop-down list of styles to be displayed on the page
<?php
/*foreach ($a as $v)
{
echo "<option>{$v [0]}</option>";
}?>
</select>
<select>
<?php
foreach ($a as $v)
{
echo "<option>{$v [1]}</option>";
}*/
?>
2. Requires a Checkbox/radio list to be displayed on the page
<?php
foreach ($a as $v)
{
Echo
"<input type= ' checkbox '/>{$v [0]}",
"<input type= ' checkbox '/>{$v [1]}.<br>";
}
?>
Inserting code
1<?PHP2 $attr=Array(3 Array("N01", "Han"),4 Array("N02", "Hui"),5 Array("N03", "Miao")6 );7?>8<select>9<?PHPTen One foreach($attr as $a) A{Echo"<option>{$a[0]} {$a[1]} </option> "; } -?> -</select> the<br/> - -<label> -<?PHP + foreach($attr as $a) -{Echo"<input type=checkbox>{$a[0]} {$a[1]}. <br/> ";} + A?> at</label>
The results displayed on the page are:
North Song Kang (Koker) 2016-06-0415:49:47
PHP Learning Notes Array traversal exercises 1