Files
2026-10-09 12:33:29 +09:00

26 lines
871 B
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
$input = "";
// 前画面で入力された文字列を変数inputに代入してください
$input = ($_POST['val']);
// numに、input(文字列)を数値変換した値を代入します
// ※ 入力された値が、数字ではなかった場合はプログラムがエラーになります
$num = intval($input); // intval(文字列)で数値変換している
//---------------------ここから本題-----------------------
/*
* 以下の仕様に沿ってプログラムを完成させてください
*
* ●1~5の数字を入力すると、入力した数字を表示
* ●1~5以外の数値を入力した場合は、「選択したのは,1~5以外です」を表示
*
* ※ プログラムは何行書いても良いです
*/
if ($num < 1 || $num > 5) {
echo "選択したのは,1~5以外です";
} else {
echo $num;
}