PHP if Statement


The if, elseif, and else statements in PHP are used to perform different actions based on different conditions.

Conditional Statements
Two conditional statements are The if...else Statement
If you want to execute some code if a condition is true and another code if a condition is false, use the if...else statement.

if ( condition )
  code to be executed if condition is true;
else
  code to be executed if condition is false;
 <html><body>
 <?php
   $day = gmdate( "D" );
   if ( $day == "" ) {
     echo '$day';
   }
   else
     echo "$day";
 ?>
 </body></html>
      Output = 
 <html><body>
 <?php
   $hour = gmdate( "H" );
   if ( $hour >  )
     echo 'date("Y")';
   else
     echo "date('Y')";
 ?>
 </body></html>
    Output =




      My girlfriend needs “space.”    
      And this is what space means, guys.    
      It means, “I need you to help me break up with you.”    
      — Yannis Pappas