PHP if else Statement

Add Tool

Use of PHP if else Statement


Learn PHP If Statement and PHP if else Statement easy way following our special php tutorial. Here we covered if condition in php and php switch statement

PHP If Statement Structure

if (condition) code to be executed if condition is true;

Type the codes below to see the result of the php if statement structure.

<?php
$date=date("D");
if ($date=="Fri")
echo "Today is Friday.";
?>

Result :You will see the message Today is Friday. If your computer's current day is Friday. Please change the day of your computer from current day to Friday. Otherwise you will see nothing. You can change the day and message that you like. Here Fri is sort form of Friday. All days have a short form like Friday. I have presented the short form of all days below for you.

Sort form of 7 days

Full name of days Sort form of Days
Saturday Sat
Sunday Sun
Monday Mon
Tuesday Tue
Wednesday Wed
Thursday Thu
Friday Fri

Use of PHP If...else StatementIf...else Statement Structure

if (condition) code to be executed if condition is true; else code to be executed if condition is false;

Type the codes below to see the result of the If...else Statement structure.

<?php
$date = date ("D");
if ($date=="Sat")
echo "Today is Saturday.";
else
echo "Please set computer date at Saturday.";
?>

Result : Here if The Day is not Saturday, You will see The second message Please set computer date at Saturday.

Use of PHP If...elseif...else Statement

Here we will play with PHP if...elseif...esle statement with the all days and will present different message of everyday.

If...elseif...else Statement Structure

if (condition) code to be executed if condition is true; 
elseif (condition) code to be executed if condition is true; 
else code to be executed if condition is true; 

Type the codes below to see the result of the If...elseif...else statement structure.

<?php
$date=date("D");
if ($date=="Sat")
echo "Today is Saturday.";
elseif ($date=="Sun")
echo "Today is Sunday.";
elseif ($date=="Mon")
echo "Today is Monday.";
elseif ($date=="Tue")
echo "Today is Tuesday.";
elseif ($date=="Wed")
echo "Today is Wednesday.";
elseif ($date== "Thu")
echo "Today is Thursday.";
elseif ($date=="Fri")
echo "Today is Friday";
else "www.1stwebsuite.com"
?>

Result : This codes will display different message at different day. I have tried to understand you about the if (PHP statement) through day. But It is not use for day but also use to display different web page for differed users and many more.


Tags: PHP If Statement, PHP if else Statement, if condition in php,php switch statement, a if, php not equal,conditional statement
Payza

About Masum Billah

Use of PHP if else Statement 1stWebSuite website seo tool is a free website ranking tool site provides a lot of on page and off page seo useful tools for you. On this site, we have a large number of website ranking tools


SIGN UP TO GET UPDATE TO YOUR INBOX




Discuss about: PHP if else Statement


adf.ly