PHP if else

The else statement executes code if the if condition specified is false. In the example below we ask ourselves if the number 10 is greater than 11.

if (10 greater than 11)
    display this text: "10 is greater than 11"
else
    display this text: "10 is NOT greater than 11"

This example will output: “10 is NOT greater than 11”

<?php
if (10 > 11) {
	echo "10 is greater than 11";
} else {
 	echo "10 is NOT greater than 11";
?>

Real world example

The last example was not very useful. Let’s take a look at a real world example. We are going to recreate the most part of one of my favorite webpages: isitfriday.org

if(current day is friday) 
    display this text: "Yes"
else
    display this text: "No"

This example will output “Yes” if the current day is Friday.

<?php
if(date("D") == "Fri") {
    echo "Yes";
} else {
    echo "No";
}
?>