Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

What are If, Nested if, if else and, Nested if else Statement in PHP?

If Statement and Nested if Statement

If statement is used to execute when a statement or a block of statement only if the condition is fulfilled or true.

Syntax

For One Statement:-

if(condition/expression)
statement;

For more than one Statement:-

if(condition/expression)
{
Blocks of statement;
}

OR

if(condition/statement):
Blocks of statements;
endif;

Sample Program

Output

Nested if Statement

We can make nesting statement by nesting the if statement. It means when we insert a second if statement inside an if statement, we call it nested if statement or nesting the if statement.

Sample Program

Output

To know more about If Statement and Nested if Statement Click here – If Statement and Nested if Statement

if else and Nested if else Statement.

A statement executes code if if_condition is true and executes another code if if_condition is false.

Syntax

if(condition/expression)
{
Statement1;
}
else echo “Statement2”;

Example – when Condition is True then, if_condition executes. See Below

Sample Program

Output

when Condition is False then, else_condition executes. See Below

Sample Program

Output

Nested if else Statement

we insert a second if_else statement inside an if_else statement, we call it nested _if_else statement.

syntax

if(condition/expression)
{
if(condition/expression)
{
Statement1;
}
else echo “Statement2”;
}
else echo “Statement2”;

Sample Program

In the above program, The first Condition is true, then it enters in 2nd condition to check and when the 2nd condition is true then it prints that statement and skips other else statements. See the Output below:

Click Here For Next Part – Difference between Single Equal, Double Equal and, Triple Equal in PHP

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
With MotoShare.in, you can book a bike instantly, enjoy doorstep delivery, and ride without worries. Perfect for travelers, professionals, and adventure enthusiasts looking for a seamless mobility solution.

Related Posts

What is CodeIgniter and use cases of CodeIgniter?

What is CodeIgniter? CodeIgniter is an open-source PHP web application framework designed to simplify and accelerate web development. It follows the Model-View-Controller (MVC) architectural pattern and provides…

Read More

What is PHP and use cases of PHP?

What is PHP? Are you wondering what PHP is and how it works? Look no further! In this article, we will explore the ins and outs of…

Read More

Complete guide on PHP certification courses, tutorials & training

What is PHP Hypertext Preprocessor is known as PHP. Many developers use PHP, an open-source server-side programming language, to create websites. In addition, it is a general-purpose…

Read More

Complete PHP with Laravel Certification Guide & tutorials

What is PHP with Laravel? PHP was visioned eventually in the fall of 1994 by Rasmus Lerdorf. PHP means Hypertext Preprocessor. It’s a extensively- used, open source…

Read More

Top 50 PHP Interview Questions and Answers

1) What is PHP? PHP is an open-source, interpreted, and object-oriented scripting language that can be executed at the server-side. PHP is well suited for web development….

Read More

Complete guide of PHP certification courses, tutorials & training

PHP is a great beginner programming language for anyone who is wanting to cross over into the coding world. Though easy to learn, it is an extremely…

Read More