Files
php-question/Question05-switch/Ex03.php
2026-10-06 12:10:09 +09:00

39 lines
1.3 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// TODO: 変数indexを宣言して、0で初期化してください
// TODO: 変数mountainを宣言して、0で初期化してください
// TODO: 変数riverを宣言して、0で初期化してください
// TODO: 変数oceanを宣言して、0で初期化してください
// 配列変数voteに、前画面で投票された5人分の値を格納します
$vote = $_POST['vote'];
// TODO: 変数indexが5未満である間繰り返す条件式を記述してください
while () {
echo ($index + 1) . '人目<br>';
echo '投票結果:' . vote[$index] .'<br>';
/* TODO:
* 以下の仕様で、switch文を記述してください
*
* ●配列vote[$index]が"山"であった場合 -> 変数mountainに1加算
* ●配列vote[$index]が"川"であった場合 -> 変数riverに1加算
* ●配列vote[$index]が"海"であった場合 -> 変数oceanに1加算
* ●配列vote[$index]が上記以外であった場合 -> 「無効票です」を出力
*/
// TODO: 変数indexに1を足して、変数indexに代入してください
}
// TODO: 変数mountain、river、oceanの中で最も票を集めたところを出力してください
// max関数を調べて活用してみましょう