drpph80800 2012-03-01 11:13
浏览 38
已采纳

我如何在这种情况下使用if / then / else?

I am having problem using the if/then/else statements.

here is my context:

$email = trim($_POST['email']);
$name = trim($_POST['name']);
$lname = trim($_POST['lname']);
$order = trim($_POST['order']);
$tel = trim($_POST['tel']);
$comments = trim($_POST['comments']);
$op ="0000-0000-0000";
$om ="mail@mail.com";
$bronze = "180 EGP/yr";
$silver ="280 EGP/yr";
$gold ="350 EGP/yr";
$plat ="420 EGP/yr";
$free ="EGP/yr";


if ($order == 'bronze') {
    echo "Please notice that your order will cost $bronze";
}

Now how can I do it again with $silver ? And so on like for silver, gold, plat and free or even if I wanna add more.

  • 写回答

8条回答 默认 最新

  • dpq39825 2012-03-01 11:27
    关注

    The switch statement would actually be a better fit for this situation:

    <?php
    $email = trim($_POST['email']);
    $name = trim($_POST['name']);
    $lname = trim($_POST['lname']);
    $order = trim($_POST['order']);
    $tel = trim($_POST['tel']);
    $comments = trim($_POST['comments']);
    $op ="0000-0000-0000";
    $om ="mail@mail.com";
    $bronze = "180 EGP/yr";
    $silver ="280 EGP/yr";
    $gold ="350 EGP/yr";
    $plat ="420 EGP/yr";
    $free ="EGP/yr";
    
    
    switch ($order) {
      case  'bronze':
        echo "Please notice that your order will cost $bronze";
        break;
      case  'silver':
        echo "Please notice that your order will cost $silver";
        break;
      case  'gold':
        echo "Please notice that your order will cost $gold";
        break;
      case  'plat':
        echo "Please notice that your order will cost $plat";
        break;
      case  'free':
        echo "Please notice that your order will cost $free";
        break;
      default:
        echo "Please choose a service package.";
        break;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(7条)

报告相同问题?

悬赏问题

  • ¥20 如何再GIS用海岸线建立缓冲区
  • ¥15 codeblock遇到问题了,求帮助😭
  • ¥15 Qt6.8.0加载网页MSVC2022
  • ¥15 360浏览器m2的这个值
  • ¥15 国内有哪些厂商做automlops的?
  • ¥15 skynet pb mysql
  • ¥15 笔记本外接显示器分辨率太低各种方法都用过了调不高
  • ¥15 Redstone R0697-F00 D2020 交换机 OS
  • ¥50 H5+js 动态数字画廊怎么做?
  • ¥20 外向内全景图像拼接相关项目和论文咨询