■test05.php 入力画面
■foreach構文版
<form action="test05_output.php" method="post">
<p>
<select name="number">
<?php
$number = array (
"10",
"20",
"30",
"40",
"50"
);
foreach ( $number as $value ) {
echo '<option value="', $value, '">', $value, '</option>';
}
?>
</select>
</p>
<input type="submit" value="送信">
■for構文版
<body>
<form action="test05_output.php" method="post">
<p>
<select name="number">
<?php
for($number = 10; $number <= 50; $number = $number + 10) {
echo '<option value="', $number, '">', $number, '</option>';
}
?>
</select>
</p>
<input type="submit" value="送信">
</form>
</body>
■while版
<body>
<form action="test05_output.php" method="post">
<p>
<select name="number">
<?php
$number = 10;
while ( $number <= 50 ) {
echo '
<option value="', $number, '">', $number, '</option>';
$number = $number + 10;
}
?>
</select>
</p>
<input type="submit" value="送信">
</form>
</body>
■test05_output.php 結果画面
<?php
$number = $_POST ['number'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xm1ns="http://www.w3.org/1999/xhtml">
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Script-Type" content="text/javascript">
<title>PHP入門</title>
</head>
<body>
<?php
echo $number;
?>
</body>
</html>