dro80463 2011-11-07 23:04
浏览 48
已采纳

如何让PHP在IF语句中回显错误?

How do i print an error if one of these are not working or rather not display some of these?

if ( $what === $toyota ) {
$print = "Camry";
} elseIF($what === $benz) {
$print = "S350";
} elseIF($what === $bmw) {
$print = "M5";
} elseIF($what === $honda) {
$print = "Accord";
} elseIF($what === $acura) {
$print = "mdx";
} elseIF($what === $jaguar) {
$print = "rx";
} elseIF($what === $landrover) {
$print = "rover";
} elseIF($what === $ford) {
$print = "sucks";
} elseIF($what === $gm) {
$print = "garbage";
} elseIF($what === $saturn) {
$print = "sat";
} elseIF($what === $jeep) {
$print = "not sure";
} elseIF($what === $chevy) {
$print = "whatever";
} elseIF($what === $porsche) {
$print = "Panamera";
} elseIF($what === $volkswagan) {
$print = "Passat";

}

print("$print");
}

}
  • 写回答

3条回答 默认 最新

  • dpz90118 2011-11-08 01:32
    关注

    Each one of your logic branches is comparing the variable $what to another variable named after a make of car. ie ($what === $honda) Where and what are you setting all these different variables to before the logic begins? Seems like it would be easier to write ($what === "honda") or use a switch statement like everyone recommends.

    Also on printing out the variable, you don't need quotes.

    Just print($print) and why not print($what) to see exactly what it is.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 用verilog实现tanh函数和softplus函数
  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题