PHP else if ladder statement


An else if ladder is a special case of nested if statement where nesting take place only in the else part when an action has to be selected based on range of value then this statement is used.
 Syntax:-
      if(condition)
          stat f1
     else if(con 2)
         stat s1
     else if(con 3)
         stat s2
     else if(con 4)
         stat s4
        ………………..
        ………………….
    else if(con n-1)
        stat n-1
    else
        stat n

Flowchart:-

else if

Example:-

MarksGrades
More than or equal 90%O(Outstanding)
80 to 89A
70 to 79B
60 to 69C
50 to 59D
40 to 49E
Less than 40Fail

W.A.P for grade based marks

 <html>
 <body>
 <?php
  $marks=75;
  if($marks>=90)
  echo“ O”;
  else if($marks>=80&&$marks<89)
  echo “A”;
  else if($marks>=70&&$marks<8`0)
  echo “B”;
  else if($marks>=60&&$marks<70)
  echo “C”;
  else if($marks>=50&&$marks<60)
  echo “D”;
  else if($marks>=40&&$marks<50)
  echo “E”;
  else
  echo “F”;
  }
  ?>
 </body>
 </html>

Output

B