If Else Conditionals in Php?

If Else statement is the most important feature of any programming language, PHP is used to run any Code Of Block according to If Else conditions. This means when we have to run some other code when the condition is true, then we use If Else if the condition is false.

Types of If Else Conditionals

  1. if Statement
  2. if…else Statement
  3. if…elseif…else Statement

1. if Statement

The if statement is executed only when the condition is true. If the condition is false then nothing is executed.



	$value = 14;

	if ($value < 20) {
		echo "Have a nice day";



2. If-else statement

There are two types of conditions in the if….else statement. One, when the condition is true then the code should be executed and when the condition is false then the statements should be executed.


	$num = 70;

    	  if ( $num > 7 ) {

        echo "Code to be executed if condition is true";
        } else {
        echo "Code to be executed if condition is false";


3. if…elseif…else Statement

It is a combination of conditional statements if…else. The only difference is that the if…else statement has been used multiple times. And more than two conditions can be executed in this.


    $age = 19;

    //If else ladder
    if ($age>18){
         echo "You are drink alcohol";
         echo "You are drink chai with water";
        echo "You can drink water only";


Related Posts

Associative Array in PHP?

An associative array is a simple and very important array of PHP. This array is also used the most, it is very easy to understand this array,…

How to work in functions PHP?

If there is any task in your program which you train to execute repeatedly then instead of writing the code for that task at a different place…

For Loofs in PHP

In for-loop initialization, condition and increment happen on the same line. The loop keeps on repeating as long as the condition is true. When the for loop…

What are operators in PHP? PHP – Operator Types

Operators are used to developing data. In Programming Languages, Operators are taken from Mathematics and Operator Programmers work with Data. An operator is a chain of symbols…

String Functions in PHP?

When many characters are written together in sequence, they form a string. For example, India is a string. It is made up of i, n, d, i,…

What is the Variable And how does it work?

The variable is seen here as a container, which you can use to store data information. It doesn’t make any difference to him, so it becomes easy…

0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x