Introduction
A conditional statement is also known as a decision statement. A decision statement is used for executing commands based on some situation or conditions. There are four types of conditional statements in PHP, which are as follows.
- if statement
- if...else statement
- if...elseif....else statement
- switch statement
The if Statements
The if statement has much importance in programming languages. An if statement executes commands when a condition is true. The syntax of an if statement is as follows:
Syntax of if statement
if (condition)
{
message ; //condition is true
}
An example of an if statement is as follows:
<?php
$age=24;
if($age<=25)
{
echo "You are a Young man" ;
}
Output
In the above code we assign the value of age is 24 and check for the condition that age is less than or equal to 25. If the assigned value of age is less than 25 i.e. condition is true then the message you are a young man is displayed.

The if...else statement
The if...else statement is also a decision statement. The if...else statement has two parts, one is if statement and second is else statement.
In the if statement we supply a condition and it blocks commands that execute when the condition is true. The else statement executes commands when the condition is false. The syntax of the if statement is as follows:
Syntax of if...else statement
if (condition)
{
message; // condition is true
}
else
{
message; // condition is false
}
An example of an if...else statement is as follows:
<?php
$percent=30;
if($percent>=33)
{
echo "You are a ed" ;
}
else
{
echo "You are Failed" ;
}
Output
In the above code we assign the percent = 30 and supply the condition (percent is greater than or equal to 33). The assigned percent is not greater than or equal to 33 i.e. condition is false, so display the message of else part, you have failed.

The if...elseif....else statement
The if...elseif....else statements are also the same as the if...else statement. The if...elseif....else statements have more than one condition and else statement. The syntax of if...elseif....else statements is as follows:
Syntax of if...elseif....else statement
if (condition)
{
message; // condition is true
}
elseif (condition)
{
message; // condition is true
}
else
{
message; // condition is false
}
An example of an if...else statement is as follows:
<?php
$percent=55;
if($percent>=60)
{
echo "You have First division";
}
elseif ($percent>=45 && $percent<60)
{
echo "You have Second division" ;
}
elseif ($percent>=33 && $percent <45)
{
echo "You have Third division";
}
else
{
echo "You are Failed";
}
?>



Amit NishadPosted Dec 1, 2021, 6:52 AM
I think you wrote an excellent blog. Thank you for sharing. I am so happy to hear that you have found this excellent blog. You can take a Top Best PHP Mcqs Questions visit us:- https://mcqpoint.com