-1

I'm trying to write a PHP statement that solves the following. My attempt is not taking. Basically I have coded items regarding heating types. I need a PHP statement that says If x = 356 then display Gas if x = 357 then display Oil if x = 358 display coal, etc, etc. Here is what I have started with and I'm a total newbie at php, please help!

    <?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 "";
}
?>
  • `=` is an assignment. You need to use `==`, the comparison operator. And after the first `if`, the others should all be `elseif` – Nick Sep 24 '19 at 22:59

1 Answers1

0

You should be looking into a case switch statement. And use default as your "else"

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";
}

REFERENCE FROM PHP.NET

Zak
  • 6,976
  • 2
  • 26
  • 48