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条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度