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.