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
You could create a simple password protected area using If/Else. You’ll most likely want to use IF with ELSE. The IF statement in PHP is very similar to using IF in real life. By now, you’ve got enough PHP knowledge under your belt to add basic PHP functionality in all of your websites. While we have not covered the entirety of basic PHP commands, the ones we have covered are among the most common and can be used in almost any web project. You can use PHP to create redirects to other pages or websites. Now, grab your AdSense code snippet from Google... In PHP, you can also use the “Require” command in place of Include. A PHP include is used when you want to include the contents of one file inside another...a very useful command! |
David Rentson
If this free PHP and MYSQL Tutorial is helpful for you... Great! Archives
October 2008
Categories
All
|