回答編集履歴

2

くじ引きっぽいのが仕様だったらしい

2019/12/07 11:21

投稿

takepan1973
takepan1973

スコア821

test CHANGED
@@ -16,7 +16,33 @@
16
16
 
17
17
 
18
18
 
19
+ ───── 2019/12/7 20:21更新
20
+
21
+ いただいた補足を元にソースを書き換えてみました。
22
+
23
+ ご確認ください。
24
+
25
+
26
+
19
27
  ```
28
+
29
+ <?php
30
+
31
+ session_start();
32
+
33
+ $max = 5; $min = 1;
34
+
35
+ if (count($_POST) === 0) {
36
+
37
+ for ($i = $min; $i <= $max; $i++) {
38
+
39
+ $_SESSION['kuji'][$i] = 0;
40
+
41
+ }
42
+
43
+ }
44
+
45
+ ?>
20
46
 
21
47
  <html>
22
48
 
@@ -28,37 +54,47 @@
28
54
 
29
55
  <?php
30
56
 
31
- $max = 5; $min = 1;
32
-
33
- $cnt = $max - $min + 1;
34
-
35
- $disp = [];
36
-
37
57
  if (isset($_POST['a0'])){
38
58
 
39
- for ($i = 0; $i < $cnt; $i++) {
59
+ echo mt_rand($min , $max);
40
60
 
61
+ } else if(isset($_POST['a1'])) {
62
+
63
+ $chk = 0;
64
+
41
- $disp[] = mt_rand($min , $max);
65
+ for ($i = $min; $i <= $max; $i++) {
66
+
67
+ $chk += $_SESSION['kuji'][$i];
42
68
 
43
69
  }
44
70
 
45
- }else if(isset($_POST['a1'])) {
71
+ if ($chk === 5) {
46
72
 
47
- while(count($disp) < $cnt) {
73
+ echo "終了";
48
74
 
49
- $tmp = mt_rand($min , $max);
75
+ } else {
50
76
 
51
- if (in_array($tmp, $disp) === false) {
77
+ $flg = true;
52
78
 
79
+ while ($flg) {
80
+
81
+ $tmp = mt_rand($min , $max);
82
+
83
+ if ($_SESSION['kuji'][$tmp] === 0) {
84
+
53
- $disp[] = $tmp;
85
+ echo $tmp;
86
+
87
+ $_SESSION['kuji'][$tmp] = 1;
88
+
89
+ $flg = false;
90
+
91
+ }
54
92
 
55
93
  }
56
94
 
57
95
  }
58
96
 
59
97
  }
60
-
61
- print implode(" ", $disp);
62
98
 
63
99
  ?>
64
100
 

1

aが不要なので削除、ほか

2019/12/07 11:21

投稿

takepan1973
takepan1973

スコア821

test CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
 
18
18
 
19
- ```PHP
19
+ ```
20
20
 
21
21
  <html>
22
22
 
@@ -68,17 +68,13 @@
68
68
 
69
69
  <div class="box">
70
70
 
71
- <form action="index.php" name = "skip" method ="POST" >
71
+ <form action="index.php" name = "skip" method ="POST">
72
72
 
73
- <input type = "hidden" name ="a" value="1">
74
-
75
- <input type = "submit" name = "a0" value="重複あり" >
73
+ <input type = "submit" name = "a0" value="重複あり">
76
74
 
77
75
  </form>
78
76
 
79
77
  <form action ="index.php" name = "next" method = "POST">
80
-
81
- <input type ="hidden" name = "a" value = "0">
82
78
 
83
79
  <input type = "submit" name ="a1" value ="重複なし">
84
80
 
@@ -94,6 +90,4 @@
94
90
 
95
91
  </html>
96
92
 
97
-
98
-
99
93
  ```