part. Syntax if (condition1) { // code to be executed if condition1 is true; } elseif (condition2) { // code to be executed if condition1 is false and condition2 is true; } elseif (condition3) { // code to be executed if condition1 and condition2 are false and condition3 is true; } else { // code to be executed if all conditions are false; } Chapter Conditional Statements in PHP version CHAPTER version CHAPTER - - - - Example : <?php $x = ; if ($x > ) { echo “x is greater than ”; } elseif ($x > ) { echo “x is greater than but not greater than ”; } elseif ($x > ) { echo “x is greater than but not greater than ”; } else { echo “x is not greater than ”; } ?> Output x is greater than but not greater than It’s important to note that only one of the blocks of code will be executed, depending on which condition is true. If none of the conditions are true, the code inside the ‘ else block ’ will be executed. .
. ‘switch’ statement This is a multiple branching statement where, based on a condition, the control is transferred to one of the many possible points. The switch statement is used to specify multiple conditions. It runs a different code block for different conditions.
Chapter Conditional Statements in PHP version CHAPTER version CHAPTER - - - - Syntax switch (expression) { case value1: //code to be executed if expression = value1; break; case value2: //code to be executed if expression = value2; break; ... default: //code to be executed if expression is not equal to any of the values; } Example : <?php $x = ; switch ($x) { case : echo “x is equal to ”; break; case : echo “x is equal to ”; break; case : echo “x is equal to ”; break; default: echo “x is not equal to , ,