我試圖弄清楚如何應用條件來檢查一年是否是閏年。但是當我添加跳躍功能時,它就不起作用了。知道如何讓它發揮作用嗎?這是我的代碼: <?php$name = "";$character = "";$email = "";$birth_year = 1969;$validation_error = "";$existing_users = ["admin", "guest"];$options = ["options" => ["min_range" => 1920, "max_range" => date("Y")]];function leap($year) { date('L', strtotime("$year-01-01")) ? TRUE : FALSE;}if ($_SERVER["REQUEST_METHOD"] == "POST") { $raw_name = trim(htmlspecialchars($_POST["name"])); if (in_Array($raw_name,$existing_users)){ $validation_error .= "This name is taken. <br>"; } else { $name = $raw_name; } $raw_character = $_POST["character"]; if (in_array($raw_character,["wizard", "mage", "orc"])) { $character = $raw_character;} else { $validation_error .= "You must pick a wizard, mage, or orc. <br>"; } $raw_email = $_POST["email"]; if (filter_var($raw_email,FILTER_VALIDATE_EMAIL)) { $email = $raw_email; } else { $validation_error .= "Invalid email. <br>"; } $raw_birth_year = $_POST["birth_year"]; if (filter_var($raw_birth_year,FILTER_VALIDATE_INT,$options)){$birth_year = $raw_birth_year;if ($raw_character === "mage") { if (!leap($birth_year)){ $validation_error .= "Mages have to be born on leap years. <br>"; }}} else { $validation_error .= "That can't be your birth year. <br>";}}?><h1>Create your profile</h1><form method="post" action=""><p>Select a name: <input type="text" name="name" value="<?php echo $name;?>" ></p><p>Select a character: <input type="radio" name="character" value="wizard" <?php echo ($character=='wizard')?'checked':'' ?>> Wizard <input type="radio" name="character" value="mage" <?php echo ($character=='mage')?'checked':'' ?>> Mage <input type="radio" name="character" value="orc" <?php echo ($character=='orc')?'checked':'' ?>> Orc</p><p>Enter an email:<input type="text" name="email" value="<?php echo $email;?>" ></p><p>
1 回答

慕婉清6462132
TA貢獻1804條經驗 獲得超2個贊
我認為你的問題是該函數沒有返回任何內容,請嘗試:
function leap($year) { return date('L', strtotime("$year-01-01")) ? TRUE : FALSE; }
- 1 回答
- 0 關注
- 118 瀏覽
添加回答
舉報
0/150
提交
取消