teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

調整

2018/07/09 10:43

投稿

yambejp
yambejp

スコア117965

answer CHANGED
@@ -12,16 +12,16 @@
12
12
  <?php
13
13
  $animal=filter_input(INPUT_GET,"animal");
14
14
 
15
- $selected=["cat"=>"","dog"=>"","rabbit"=>""];
15
+ $selected["animal"]=["cat"=>"","dog"=>"","rabbit"=>""];
16
- $selected[$animal]=" selected";
16
+ $selected["animal"][$animal]=" selected";
17
17
 
18
18
  print <<<eof
19
19
  <form method="get">
20
20
  <select name="animal">
21
21
  <option value="">----</option>
22
- <option value="cat"{$selected["cat"]}>猫</option>
22
+ <option value="cat"{$selected["animal"]["cat"]}>猫</option>
23
- <option value="dog"{$selected["dog"]}>犬</option>
23
+ <option value="dog"{$selected["animal"]["dog"]}>犬</option>
24
- <option value="rabbit"{$selected["rabbit"]}>うさぎ</option>
24
+ <option value="rabbit"{$selected["animal"]["rabbit"]}>うさぎ</option>
25
25
  </select>
26
26
  </form>
27
27
  eof;
@@ -29,4 +29,5 @@
29
29
  print htmlspecialchars($animal);
30
30
  }
31
31
  ?>
32
- ```
32
+ ```
33
+ ※微調整しました