Tuesday, 5 January 2016

PHP - Conditionals statement

There are Three Types  conditional statement in PHP

1. IF Statement

2. ELSE IF Statement

3. SWITCH Statement


The IF ELSE Statement

In if statement you like to match You drive to on, And other wise you drive to off.
Syntex : 

<?php


  if ($gender == 'Male')  {    

   $gender = 'This is MALE';

}else{

  $gender = 'This is FEMALE';




The ELSE IF Statement

In if statement you like to match multiple condition or multiple opportunity to drive multiple desition.
Syntex : 

<?php


  if ($color == 'Green')  {    

  echo "This is Green Color";

}else if ($color == 'Red'){

  echo "This is Red Color";

}else if ($color == 'Yellow'){

  echo "This is Yellow Color";

}else {

  echo "No any colour match";

}



The SWITCH Statement
  
The switch statement is useful in cases in which one variable or the result of an expression can have multiple values to match one value.


<?php  

switch ($color)  {
    case "Red":       
        echo "You selected Red";       
        break;    
   case "Yellow":       
        echo "You selected Yellow";        
        break;    
   case "Black":        
        echo "You selected Black";        
        break;   
   case "Purpal":       
        echo "You selected Purpal";        
        break;    
   case "Blue":       
        echo "You selected Blue";       
         break;  
}
 ?>