制御構造ループ 5−2
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="ja"><head>
<meta http-equiv="Content-type" content="text/html; charset=EUC-JP">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="stylesheet" href="../style.css">
<title>動物グループ分け</title></head>
<body><div class="file2">
<form action="05_02_loop.php" method="post">
12匹を4匹のグループに分けて、表示を押すたびにシャッフルします。
<input type="submit" value="表示!"></form>
<?php
error_reporting(1);
$member=array("クマ","ネコ","アヒル","イヌ","ゾウ","キリン","ウマ","イルカ","サル","ウシ","ネズミ","トラ");
srand(date(s)); /*時刻-秒を使って乱数を初期化*/
shuffle($member); /*配列memberをシャッフル*/
$a = 0 ; /*番号カウント*/
echo "<table border ='1'><tr>";
while($a < 12) { /*繰り返し、aが12がより小さい間実行*/
echo "<td width='120' align='center'>".$member[$a]."さん¥n</td>";
if($a == 11){ /*テーブルの終了*/
echo "</tr></table>";
} else if($a%4 == 3){
echo "</tr><tr>¥n"; /*テーブルの改行*/
} else {
}
$a++;
}
?> </div></body></html>