The if Statement PHP

Lays out the form of an if statement.

The form of an if statement.

form of an if statement.

The if statement executes a statement if the expression inside the parentheses evaluates to true; otherwise the code is skipped. It may be a single statement followed by a semicolon. Usually it's a compound statement surrounded by curly braces. An else statement may appear immediately after the statement and has a statement of its own. It, too, may be either single or compound. It is executed only when the previous expression is false. In between an if statement and an else statement you may put as many elseif statements as you'd like. Each elseif expression is evaluated in turn, and control skips past those that are false. If an elseif statement evaluates to true, then the rest of the code in the greater if statement is skipped. That is to say, only one match will be made.demonstrates an if-else statement.

Of course, you are not obligated to have an elseif or an else. Sometimes you mightwant to build a very simple if statement.You can use if to build a series of checks that covers all possible cases. Just start by checking for the first condition with an if; then check for each following condition with an elseif. If you put an else at the end, you will have accounted for all possible cases. uses this method to print the day of the week in German. The script gets today's name and then compares it to the days Monday through Saturday. If none of these match, it is assumed to be Sunday.

An if-elseif-else Statement

<?
if($name == "")
{
print("You have no name.");
}
elseif(($name == "leon") OR ($name == "Leon"))
{
print("Hello, Leon!");
}
else
{
print("Your name is '$name'.");
}
?>

A Simple if Statement

<?
if(date("D") == "Mon")
{
print("Remember to put the trash out.");
}
?>

Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

PHP Topics