PHP - Using nested if statement

Introduction

You can use an if statement inside another if statement:

Demo

<?php

     $widgets = 23;//  w w w. j  a va  2s  . com
     if ( $widgets  >= 10 ) {
        if ( $widgets  <= 20 ) {
           echo "We have between 10 and 20 widgets.";
        }
     }
?>

The code block between the braces of the first if statement is itself another if statement.

The first if statement runs its code block if $widgets >= 10 , whereas the inner if statement runs its code block.

Related Topic