PHP If, Else and Elseif
PHP Tutorial » PHP If, Else and Elseif
What does PHP If, Else and Elseif do?
The conditional if, else and elseif statement is used to execute a block of statements based on the particular condition.
Different types of ‘if..else elseif’ statements can be used in PHP for implementing conditional statements.
In PHP we have a few statements that you can use to make decisions as:
- if statement
- if...else statement
- if...elseif....else statement
Syntax if Statement:
if (condition) {
code to be executed if condition is true;
}
?>
Syntax if...else Statement:
if (condition) {
code to be executed if condition is true;
} else {
code to be executed if condition is false;
}
?>
Syntax if...elseif...else Statement:
if (condition) {
code to be executed if this condition is true;
} elseif (condition) {
code to be executed if first condition is false and this condition is true;
} else {
code to be executed if all conditions are false;
}
?>
PHP - if Statement
if statement executes some code if until one condition is true.
<?php
$numbr=38;
if($numbr<70){
echo "$numbr is less than 70";
}
?>
Output: 38 is less than 70
Related subjects:
PHP syntax
What is an array
PHP variabl
Array to comma separated
Tags: php if statement, php if else html, php if else shorthand, php if/else inline, <? php else: ?>, php if else without brackets, php if multiple conditions, php if not, ternary operator
php if in array, if file exists, if not, multiple conditions, and, or
PHP - if...else Statement
if...else statement executes some code if a condition is true and another code if that condition is false.
<?php
$numbr=38;
if($numbr<70){
echo "$numbr is less than 70";
}
else {
echo "$numbr is greater than 70";
}
?>
To see the result of the PHP code above please click Execute
PHP if...elseif...else Statement
The if ... elseif ... else statement executes different codes for more than two conditions.
<?php
$numbr=38;
if($numbr<70){
echo "$numbr is less than 70";
}
elseif ($numbr > "70") {
echo "$numbr is greater than 70";
} else {
echo "$numbr is equal 70";
}
?>
php if statement, php if else html, php if else shorthand, php if/else inline, <? php else: ?>, php if else without brackets, php if multiple conditions, php if not, ternary operator
php if in array, if file exists, if not, multiple conditions, and, or
PHP if, else and elseif Statements - php tutorial
This tool makes it easy to create, adjust, and experiment with custom colors for the web.

Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.

Find here examples of creative and unique website layouts.

Find here examples of creative and unique website CSS HTML menu.