·  PHP – Syntax – Statements – Conditional – elseif

 

- Info:

  - Multiple elseif statements can be used in combination with if statement.

  - if...elseif combo works as multiple if statements.

  - Conditions are evaluated in sequence and only code belonging to the first condition which evaluates to true is executed.

  - if...elseif combo can optionaly end with else statement.

    If so, then if all conditions evaluate to FALSE only code belonging to else statement will be executed.

 

- Syntax:

  if     (condition1) { code1  }

  elseif (condition2) { code2  }

  ...

  else                { code10 }

 

- Example:

  - Creat PHP Console Application Test.php.

 

    Test.php

    <?php

 

      $number = 10;

      $text   = "Hello";

        

      if     ($number ==  10    ) { print "Number is 10";      }  

      elseif ($text   == "Hello") { print "Text equals Hello"; }

      elseif ($text   == "World") { print "Text equals World"; }

      else                        { print "No match found";    }

 

    ?>