PHP 带有 or 条件的大小写切换

我正在尝试使用带有“或”的 SWITCH CASE 条件来获取从表单收到的一个或其他值。但总是进入第一个条件“这里!” 1'。有人可以帮我找出代码中的错误吗?我已经尝试使用 [('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>';

          

        }


达令说
浏览 71回答 1
1回答

守候你守候我

问题是,case如果您使用逻辑运算符,则 ur 的计算结果为布尔值。所以当你有case ('ate_201803'||'201804_201902')PHP 时会看到case true.要使用等效项,OR只需将以下情况依次列出:switch ($value) {&nbsp; case 'ate_201803':&nbsp; case '201804_201902':&nbsp; &nbsp; // ...&nbsp; break;}
打开App,查看更多内容
随时随地看视频慕课网APP