PHP Tutorial Part 5 [if, if-else, elseif and switch statements]
PHP Video Tutorial Part 5
Part 5: Documentation + Video [if, if-else, elseif and switch statements]
Download Link :
Size: 5.65 MB
And Also you can check all older and Incoming tutorials here :
Tutorial Links
“DOCUMENTATION“
Hello Friends,
Welcome To PHP Tutorial Part 5
Topic Covered: if, if-else, elseif and switch statements
Well I think you read my first tutorial PHP part 1, 2, 3 if not then kindly download from here:
- Go to PHP folder and download rest all Parts of PHP tutorial.
____________________________________________________________________________________________
Today we will discuss if, if-else, elseif and switch statements
1. If Statement:
If you want to execute some code if the condition is true, then use the if statement. Let’s take a look at syntax:

The code will execute only if the condition is true, In this case the condition will not satisfied so the code will not execute.
<?php
$a=2;
$b=3;
if ($a > $b) {
echo “a is greater than b”;
}
?>
You can check in this case there is no output. So just swap the values. And you will find it will show you “a is greater than b”.You can Try Using the other Boolean expressions also i.e. Logical and comparison operators
1. If – else statements :
If you want to execute some code if one condition is true, and in another code if first condition is false, use the if – else statement.
Take a look above at syntax:
<?php
$a=3;
$b=2;
if ($a > $b){
echo “a is greater than b”;
}
else {
echo “b is greater than a”;
}
?>
3. ElseIf Statement:
We have another option if you want to execute some code in which more than one or several conditions are true then use the elseif statement.lets check the syntax of elseif:

4. Switch Statement:
If you want to execute one statement from number of statements, then use the Switch statement. This is more efficient method than previous one. Take a look at syntax:

If the expression has value equal to value 1 then it will execute the statement inside it and break is used to terminate and go. If the expression has not equal to any value then it will execute default loop. In default its optional break.
Take a look at program:
<?php
$a = 2;
switch ($a)
{
case 0:
echo “a has value = 0″;
break;
case 1:
echo “a has value = 1″;
break;
case 2:
echo “a has value = 2″;
break;
default:
echo “a is not equal to 0,1,2″;
break; // optional using break at the last
}
?>
Hope you enjoying the tutorial.
If any problems mail me at: encarta.mann@gmail.com
Thanks for reading this documentation. Continue in Next Edition ….
Thanks,
LM Team!






KonstantinMiller
6 Jul, 2009
Hi. I like the way you write. Will you post some more articles?
mercerd
20 Jul, 2009
interesting material, where such topics do you find? I will often go
Root_Admin
21 Jul, 2009
Its not find! i himself made all
gunawan
9 Aug, 2010
good,
thank you for the information,
This was helped,
spirit! ! ! ! !
jobvacancy
12 Aug, 2010
thank you for the information,
This was helped,
spirit! ! ! ! !