• In the previous post we looked upon else…if ladder and in this post we will focus on another form of if statement that is nested if statement.
  • When one if statement contains another if statement then such type of structure is known as nested if.
  • Nested if structure also helps in multi-way decision making where one condition depends on other.
  • It has the following form:
if (condition 1)
{
   if (condition 2)      / * nested if */
   {
       Statement(s);
   }
   else
   {
       Statement(s);
   }
}
else
{
   Statement(s);
}

Example:

<?php
       if (category==”sport”)
       {
           if (gender==’m’)
           {
               mark=mark+bonus_mark;
           }
       }
       else
       {
           mark=mark+5;
       }
?>