Category Archives: PHP

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";
}
?>

PHP if

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

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

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

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

So for what ever weird reason 11 is not greater than 10, we could have something nice to show then also. Take a look at: PHP if else.

Real world example

The last example was kind of stupid. Lets take a look at a more usefull example. We are going to recreate the most part of one of my favorite webpages: isitfridayyet.net

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

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

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

To recreate the whole website, we also need to tell our visitors that it isn’t friday, if it is not… Go ahead to the: PHP if else.