10c05-1.php

来自「介绍PHP5的给类型函数应用」· PHP 代码 · 共 39 行

PHP
39
字号
<?php// If this file was a submission, then output the valuesif (count($_POST)) {    echo "<p>You submitted the following music ID numbers:<br />1st - {$_POST['1st']}, 2nd - {$_POST['2nd']}, 3rd - {$_POST['3rd']}</p>";}// Array of options in a format that might have come from a database query:$types = array(    array('id' => 10, 'desc' => 'Rock'),     array('id' => 11, 'desc' => 'Alternative'),    array('id' => 12, 'desc' => 'Metal'),     array('id' => 20, 'desc' => 'Classical'),    array('id' => 33, 'desc' => 'Jazz'),     array('id' => 34, 'desc' => 'Blues'),    array('id' => 42, 'desc' => 'Ska'),     array('id' => 44, 'desc' => 'Folk'),    array('id' => 49, 'desc' => 'Blue Grass')    );// Now, generate the options portion of a select string, based upon this:// Start with a blank option:$options = "<option value=\"\">Select one ...</option>\n";// Now loop over all possibilities, adding them in:foreach ($types as $m) {    $options .= "<option value=\"{$m['id']}\">{$m['desc']}</option>\n";}// And now we can output our page, using this multiple times:?><form action="<?= $_SERVER['PHP_SELF'] ?>" method="post" name="f1"><p>Please choose your favorite types of music:</p><p>1st: <select name="1st"><?= $options ?></select></p><p>2nd: <select name="2nd"><?= $options ?></select></p><p>3rd: <select name="3rd"><?= $options ?></select></p><p><input type="submit" /></p></form>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?