The IF/ELSE statement is wonderful if you need to check for only one condition.
But, what if you need to check for multiple conditions?
Like, for instance, IF a truck is a Dodge, do this...ELSE a truck is a Chevy, do this...but what if you need to have options if a truck was a Ford?
In this example, we simply want to see if a truck is a Dodge or not.
We can do this with IF / ELSE...
<php
$truck = "Chevy";
if($truck == "Dodge"){
echo "It’s Ram Tough!";
} else {
echo "We’ll Be There!";
}
?>
Now, if we wanted to see if the truck was a Ford, we’d add the ElseIf statement...
<php
$truck = "Chevy";
if($truck == "Dodge"){
echo "It’s Ram Tough!"; }
elseif {$truck == “Ford”}
echo “Built Ford Tough!”;
} else {
echo "We’ll Be There!";
}
?>
...And so on.
You could continue to use Elseif to declare other Trucks.
One thing to remember about Elseif is that it can’t be used without IF.
0 Comments
|
David Rentson
If this free PHP and MYSQL Tutorial is helpful for you... Great! Archives
October 2008
Categories
All
|