lundi 8 juin 2015

How to compress an if statement code?

So I have a variable named bestmatchrule which returns a single number between 1-25 and now Im trying to assign that number a name using the following if statement:

$a=$bestmatchrule;
$b='';

if ($a == "1" || "2") {
      $b="Chesil House";
} elseif ($a == "3" || "4") {
      $b="Corfe House";
} elseif ($a == "5" || "6") {
      $b="Cranborne House";
} elseif ($a == "7" || "8") {
        $b="Dorchester House";
} elseif ($a == "9" || "10") {
      $b="Lyme Regis House";
} elseif ($a == "11" || "12") {
      $b="Okeford House";
} elseif ($a == "13" || "14") {
      $b="Purbeck House";
} elseif ($a == "15" || "16") {
      $b="Student Village";
} elseif ($a == "17" || "18" || "19") {
      $b="Unilet";
} elseif ($a == "20") {
      $b="Conel Court";
} elseif ($a == "21" || "22") {
      $b="St John's Road";
} elseif ($a == "23" || "24" || "25") {
      $b="Private Let";
} else {
     "Please Try Again";
}

Problem is it doesn't work. It only returns the top one. Is this an issue with the value returned or the if statement?

Also, if there a way of shortening it to make it look nicer? I'm more focused on functionality, but there has to be a better way than this?

Thanks in advance! (p.s. sorry for the noob question!)

Aucun commentaire:

Enregistrer un commentaire