PHP IF…ELSE-IF

Conditional statements are used to perform different actions based on different conditions.

PHP contains following conditional statements

  • if statement
  • if…else statement
  • if…else if…else statement
  • switch statement

IF Statement

Simple if statement contains only one response if condition is true.

<?php

$day=strtoupper(date("D"));
if($day=="FRI")
	echo "Have a Nice Weekend!";

?>
	

IF Else Statement

if else statement contains response for both true & false conditions

<?php
$day=strtoupper(date("D"));

if($day=="FRI")
	echo "Have a Nice Weekend!";
else
	echo "Have a Nice Day!";
?>
	

IF…ELSE-IF…ELSE Statement

IF…ELSE-IF…ELSE is used in multiple conditions scenario.

<?php

$day=strtoupper(date("D"));
if($day=="FRI")
	echo "Have a Nice Weekend!";
else if($day=="SUN")
	echo "Have a Nice Sunday!";
else	
	echo "Have a Nice Day!";

?>