亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使變量具有多個值,并使這些值在輸入標簽中有效?

如何使變量具有多個值,并使這些值在輸入標簽中有效?

PHP
RISEBY 2023-03-04 17:58:12
所以我做了一個表單密碼系統,我遇到了這個問題,我嘗試輸入數組中的值,密碼仍然錯誤?(我將“batanes”或“Batanes”放入輸入并提交,但由于某種原因它不是正確的密碼。即使它是數組中的確切值)<form id="pass"  method="POST">            <b><label for="Pass"> Where is our Ultimate Travel Destination Wish List in the Philippines?   </label></b>            <input id="Pass" name="Pass" type="text" placeholder="Enter Password Here..." required>            <input type=submit>             <?php            error_reporting(0);                $pass= array("Batanes", "batanes");                $enter= $_POST['Pass'];                if ($enter === $pass) {                    echo <<<EOL                      $('<div class=overlay></div>').bind('mouseover',function(){    });    $(<div class="popup"> Good Job Man! <br> Now to the next! </div>).bind('mouseout', function(){                  });    <script>        setTimeout(function(){ window.location.href = 'mommysthirdimahe.html'; }, 2000);    </script>    EOL;    exit;    }    elseif ($enter === NULL) {     echo "";     }我如何做到這一點,以便當 $enter 等于 $pass 數組中的值時,它執行“if”中的函數?
查看完整描述

1 回答

?
慕神8447489

TA貢獻1780條經驗 獲得超1個贊

該問題的答案是in_array函數。


例子:


if (in_array($enter, $pass)) {

? ? // execute whatever you want

}

我注意到您在數組中存儲了兩次“Batanes”字樣$pass,以處理區分大小寫的檢查。取而代之的是,您可以僅存儲小寫版本并使用strtolower函數將輸入也轉換為小寫。


例子:


$pass = ['batanes'];

if (in_array(strtolower($enter), $pass)) {

? ? // execute whatever you want

}

但是在這種情況下,您不再需要數組,您可以簡單地使用它:


if ($pass === $enter) {

? ? // execute whatever you want.

}


查看完整回答
反對 回復 2023-03-04
  • 1 回答
  • 0 關注
  • 147 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號