There are four types of conditional statements available in PHP.
1. PHP If Statement
In this statement a block of code is executed only if the condition is true.
if (condition) { // block of statements to be executed. }
2. PHP If..else Statement
In this statement, first block of code is executed only if the condition is true; otherwise second block of code is executed.
if (condition) { // first block of statements to be executed. } else { // second block of statements to be executed. }
3. PHP If..elseif..else Statement
In this statement, first block of code is executed only if the condition is true. If first condition fails then elseif condition is checked, if it is true then its block of code will be executed, otherwise else block of code is executed.
if (condition) { // first block of statements to be executed. } elseif (condition) { // elseif block of statements to be executed. } else { // else block of statements to be executed. }
4. PHP Switch Statement
The switch statement is to choose one option out of list of options.
switch (num) { case 1: //code to be executed if num=1; break; case 2: //code to be executed if num=2; break; default: //code to be executed if No match found; break; }