php - PHP IF 语句要使用 Else If 还是另一个 IF 语句?
问题描述
我正在尝试编写一个解决以下问题的 PHP 语句。我的尝试没有采取。基本上我有关于加热类型的编码项目。我需要一个 PHP 语句,上面写着 If x = 356 then display Gas if x = 357 then display Oil if x = 358 display coal等等。这是我开始的,我是php的新手,拜托帮助!
<?php
function heatfuel_function( $heatfuel ) {
if ( heatfuel = "543" ) {
echo "Electric";
}
if (heatfuel = "544") {
echo "LP Gas";
}
if (heatfuel = "545") {
echo "Natural Gas";
}
if (heatfuel = "546") {
echo "Natural Available Gas";
}
if (heatfuel = "550") {
echo "Multi Fuel";
}
if (heatfuel = "552") {
echo "Oil Fuel";
}
if (heatfuel = "556") {
echo "Wood Fuel";
}
} else {
echo "";
}
?>
解决方案
你应该调查一份case switch
声明。并default
用作您的“其他”
IE
switch ($heatfuel) {
case 543:
echo "LP Gas";
break;
case 545:
echo "Natural Gas";
break;
case 546:
echo "Natural Available Gas";
break;
// As many cases as you want ..
default:
echo "None of the above";
}
推荐阅读
- r - 从矩阵中所有可能的拆分组合中找到最小和
- python - Python代码保留了大量的内存
- c# - 在 C# 中更新 DatagridView 图像列
- java - 当参数正确时,为什么我会在绘制方法上出现错误?
- python - 如何从 ValuesView 中获取价值?试图理解我的机器人的 Dialogflow 响应
- c++ - C ++ ROOT:IncrementalExecutor::executeFunction:链接时符号'_ZStorSt13_Ios_OpenmodeS_'未解析[cling接口函数]
- javascript - Jquery 的“GetJson”功能不适用于移动设备上的 URL
- python - 导入错误:没有模块名称 sklearn.external.six
- excel - 创建 2 个日期之间的 30 分钟时间间隔列表
- javascript - 将 JavaScript 值传递给 ASP.NET Core 控制器