PHP conditional statements if else

Very frequently when you write code, you want to do different proceedings for different decisions. You can use conditional statements in your code to do this.
In PHP we have the following conditional statements:
  1. if statement - executes block of code only if a specific condition is true
  2. if...else statement - executes block code if a condition is true and another code if the condition is false
  3. if...elseif....else statement - specifies a new condition to test, if the first condition is false
  4. switch statement - selects one of many blocks of code to be executed
Suppose we have Two digits and we want to check which one is greater than second.
PHP Code:
  1. <?php
  2.  
  3.  $FirstNumber = 10;
  4.  
  5. $SecondNumber = 30;
  6.  
  7. ?>

and we have if condition which will show us the greater number. every if statement depends on a condition where we compare the values. like if( condition is true ) then execute the { this block of code}


PHP Code:
  1. <?php
  2.  
  3.  $FirstNumber = 10;
  4.  
  5. $SecondNumber = 30;
  6.  
  7.  if($FirstNumber <  $SecondNumber)
  8.  {
  9.  
  10.  echo "First number is less than second number";
  11.  
  12. }
  13.  
  14. ?>
We also can check the multiple condition by using the nested if else statements. a correct syntax of nested if else if statement given below.
PHP Code:
  1. <?php
  2.  
  3. if(condition)
  4. {
  5. do some thing here 
  6. }
  7. else if(condition)
  8. {
  9. do some thing here 
  10. }else
  11. {
  12. this is default both condition are false then do some thing here
  13. }
  14.  
  15. ?>
First of all if condition will be checked if it is true then first only first code block will be executed and if it is false then second else if condition will be checked if it is true then below code block will be executed and so on... . if both of above conditions are false then else code block will be executed.