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 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法
  • ¥15 很想要一个很好的答案或提示
  • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
  • ¥15 怀疑手机被监控,请问怎么解决和防止
  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区