我正在尝试编写解决以下问题的PHP语句。我没有尝试。基本上,我已经编码了有关加热类型的项目。我需要一个PHP语句,如果x = 356,然后显示Gas,如果x = 357,然后显示Oil,如果x = 358,则显示煤炭,依此类推。等等。这就是我刚开始的工作,我是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 "";
}
?>
答案 0 :(得分:0)
您应该查看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";
}