配列の並べ替え 12−1
<!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 method="post" action="12_01_sort.php">
<input type="submit" name ="num" value="1">
<input type="submit" name ="num" value="2">
<input type="submit" name ="num" value="3">
<input type="submit" name ="num" value="4">
<input type="submit" name ="num" value="5">
1〜5のどれかが正解、絵がそろいます。正解は毎回変わります。</form>
<?php
error_reporting(1);
$car = range(1,9);
shuffle($car); /*配列carをシャッフル*/
$rand = rand(1,5);
if($_POST['num'] ==$rand){
sort($car);
}
$a = 0 ; /*番号カウント*/
echo "<table border ='0' cellspacing='0' cellpadding='0'><tr>";
while($a < 9) { /*繰り返し、aが12がより小さい間実行*/
echo "<td align='center'>"."<img src='img/car/car0".$car[$a].".jpg'></td>¥n";
if($a == 8){ /*テーブルの終了*/
echo "</tr></table>";
} else if($a%3 == 2){
echo "</tr><tr>¥n"; /*テーブルの改行*/
} else {
}
$a++;
}
echo "<br>正解は $rand でした。";
$data="10";
?> </div></body></html>