if – elseif – else
Well, this is the tutorial for a if – elseif – else statement. I just assume that you’re already familiar with the if construct and the else statement. Now, i will explain the elseif part, as it might be very useful for you.
Example if – elseif – else
if (expression)
{
// Code if true
}
elseif (expression)
{
// Code if true
}
elseif (expression)
{
// Code if true
}
else
{
// Code if all are false
}
So, as you can see, there is not only a if and else statement present. Now we have the elseif as well. The deal here is just that you can provide expressions for each of the elseif statements. For each of the expressions a block of code is reserved between the accolades ({ }). If the expression evaluates true, the code between the { and } will be performed by the php engine. If all the expressions evaluates false, the (already known) else statement will take the lead and will be performed by the php engine.
Moreover, you can add as many elseif statements as you like, without having limitations. Unfortunately how more you are using, how more confusing it will be if you don’t write on a decent manner. Therefor i personally recommend the switch statement, but that’s not really the subject here isn’t it…..
Well, this is pretty simple right ?
Some more examples
if (5 > 6)
{
// Code if true
}
elseif (5 == 6)
{
// Code if true
}
elseif (5 != 6)
{
// Code if true
}
else
{
// Code if false
}
if (5 > 6): // Code if true elseif (5 == 6): // Code if true elseif (5 != 6): // Code if true else: // Code if false endif;
Mail this!
- Comments (1)
- PingBacks (0)
- TrackBacks (0)
-
2010-10-26 08:30:41Thank you. – behindvfx

