I've got some code using a lot of complex if statements that I'm using for a VIN decoder. I finally got it working and I'm hesitant to alter it but these if statements are huge! If a switch statement could be used to accomplish what the if statements are doing, could someone give me an example using my data? Here's a snippet of code:
$ModelYear=substr($decode,5,1);
$AssemblyPlant=strtoupper(substr($decode,6,1));
if ($AssemblyPlant == "2" && ($ModelYear >= 5 && $ModelYear <= 7)){
echo "$AssemblyPlant = St. Therese, Canada<br />";
} elseif ($AssemblyPlant == "7" && $ModelYear == "9"){
echo "$AssemblyPlant = Lordstown, OH<br />";
} elseif ($AssemblyPlant == "B" && $ModelYear == "7"){
echo "$AssemblyPlant = Baltimore, MD<br />";
} elseif ($AssemblyPlant == "C"){
echo "$AssemblyPlant = Southgate, California<br />";
} elseif ($AssemblyPlant == "E" && ($ModelYear >= 6 && $ModelYear <= 9)){
echo "$AssemblyPlant = Linden, NJ<br />";
} elseif ($AssemblyPlant == "G"){
echo "$AssemblyPlant = Framingham, Massachusetts<br />";
} elseif ($AssemblyPlant == "H"){
echo "$AssemblyPlant = Flint, Michigan<br />";
} elseif ($AssemblyPlant == "K" && ($ModelYear >= 5 && $ModelYear <= 7)){
echo "$AssemblyPlant = Leeds, MO<br />";
} elseif ($AssemblyPlant == "L" && ($ModelYear >= 3 && $ModelYear <= 7)){
echo "$AssemblyPlant = Van Nuys, CA<br />";
} elseif ($AssemblyPlant == "N" && $ModelYear == "4"){
echo "$AssemblyPlant = Norwood, OH<br />";
} elseif ($AssemblyPlant == "T" && ($ModelYear >= 6 && $ModelYear <= 9)){
echo "$AssemblyPlant = Tarrytown, NY<br />";
} elseif ($AssemblyPlant == "U" && $ModelYear == "8"){
echo "$AssemblyPlant = Lordstown, OH<br />";
} elseif ($AssemblyPlant == "W" && ($ModelYear >= 8 && $ModelYear <= 9)){
echo "$AssemblyPlant = Willow Run, MI<br />";
} elseif ($AssemblyPlant == "X"){
echo "$AssemblyPlant = Fairfax, Kansas<br />";
} elseif ($AssemblyPlant == "Y" && ($ModelYear >= 2 && $ModelYear <= 5)){
echo "$AssemblyPlant = Wilmington, Delaware<br />";
} elseif ($AssemblyPlant == "Z"){
echo "$AssemblyPlant = Fremont, California<br />";
} else {
echo "Buick's weren't built at this plant in 197$ModelYear. Please check your VIN and try again.<br />";
}
Thanks!