PHPの教科書5 繰り返し文
while文やfor文を使って、ドロップダウンメニューを作成
http://felica.boy.jp/textbook/lecture1-2-1.php
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>よく分かるPHPの教科書</title> </head> <body> <p>while文</p> <select name="age" id="age"> <?php //while文で繰り返し $i = 10; while ($i<=70) { print('<option value="' .$i. '">' .$i. '歳</option>'); $i++; } ?> </select> <br> <p>for文</p> <select name="age" id="age"> <?php //for文で繰り返し for ($i=10; $i<=70; $i++) { print('<option value="' .$i. '">' .$i. '歳</option>'); } ?> </select> <br> <p>for文偶数</p> <select name="age" id="age"> <?php //for文で繰り返し for ($i=10; $i<=70; $i=$i+2) { print('<option value="' .$i. '">' .$i. '歳</option>'); } ?> </select> </body> </html>