Nested if statements in PHP

Nested if statements means an if block inside another if block. Shortly a control structure inside another control structure.

It structure will look like

if (expression 1 )
{
if (expression 2 )
{
// statements 1
}
else
{
// Statements 2
}
}
else
{
if ( expression 2)
{
// Statements 3
}
else
{
// Statements 4
}
}

Here we can see another if .. else structure inside the if block and else block. Like this we can add any number of nested if else statements.

Nested if statements will make the PHP codes more comples and lengthy. To avoid Nested statements we can opt for elseif statements

Exit mobile version