我正在嘗試使用帶有“或”的 SWITCH CASE 條件來獲取從表單收到的一個或其他值。但總是進入第一個條件“這里!” 1'。有人可以幫我找出代碼中的錯誤嗎?我已經(jīng)嘗試使用 [('value1' || 'value2')] 和 ['value1' || 'value'] 兩者都不起作用,因為總是返回“變量 DDDs 的值是:$sDDDs - 這里!1”<?php$sDDDA = $_POST['DDDA'];$sNumA = $_POST['NumA'];$sDtInit = $_POST['DtInit'];$sDtEnd = $_POST['DtEnd'];$sIdProduct = $_POST['IdProduct'];$sAnoMes = $_POST['AnoMes'];$sDDDs = $_POST['DDDs'];$sMSISDN = $_POST['DDDA'] . $_POST['NumA'];$s55MSISDN = "55" . $_POST['DDDA'] . $_POST['NumA'];echo "The value of the variable DDDA is: $sDDDA <br>";echo "The value of the variable NumA is: $sNumA <br>";echo "The value of the variable DtInit is: $sDtInit <br>";echo "The value of the variable DtEnd is: $sDtEnd <br>";echo "The value of the variable AnoMes is: $sAnoMes <br>";echo "The value of the variable DDDs is: $sDDDs <br>";echo "The value of the variable MSISDN is: $sMSISDN <br>";echo "The value of the variable 55MSISDN is: $s55MSISDN <br>";echo "</b><br><br>";switch($_POST['IdProduct']){case 'Conecta':echo "The value of the variable IdProduct is: $sIdProduct - here! <b>1</b><br><br>"; switch ($_POST['AnoMes']){ case ('ate_201803'||'201804_201902'): echo "The value of the variable AnoMes is: $sAnoMes - here! <b>1</b><br><br>"; switch ($_POST['DDDs']){ case '1x4x5x6x': echo "The value of the variable DDDs is: $sDDDs - here! <b>1 - 1x </b><br><br>"; break; case '2x3x7x8x9x' : echo "The value of the variable DDDs is: $sDDDs - here! <b>1 - 2x </b><br><br>"; break; default: echo 'ERRO! The value is wrong for variable DDD! here! <b>1</b><br><br>'; }
1 回答

守候你守候我
TA貢獻1802條經(jīng)驗 獲得超10個贊
問題是,case如果您使用邏輯運算符,則 ur 的計算結(jié)果為布爾值。
所以當你有case ('ate_201803'||'201804_201902')PHP 時會看到case true.
要使用等效項,OR只需將以下情況依次列出:
switch ($value) {
case 'ate_201803':
case '201804_201902':
// ...
break;
}
- 1 回答
- 0 關(guān)注
- 135 瀏覽
添加回答
舉報
0/150
提交
取消