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

PHP – strip_tags() Replace with Spaces Example

We are going to learn php strip tags with spaces. You will learn how to replace php Strip_tags with space. In this article, we will replace php…

How to Get Duplicate Values from Array in PHP?

We will learn php array get duplicate values. we will help you to give an example of how to get duplicate values from array in php. you…

PHP explode() Function Example Tutorial

A PHP explode function example is given in this article. I will demonstrate how to use PHP’s explode string to array function. This is a basic example…

How to Convert Array to String in PHP?

We will cover the example of converting an array to a string in PHP in this lesson. We’ll examine an example of converting an array to a…

How Can I Convert a String in PHP Into an Array?

We will go over how to transform a string into an array in PHP in this little tutorial. Describe how to convert a string value into an…

How to Use the array_merge() Function in PHP?

We will go over the simple and quick method to use the PHP array_merge() function example in this brief tutorial. Let’s talk about the PHP example of…

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