AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL

PHP If, Else and Elseif


<< Previous Page
PHP Operator Type
Next Page >>
PHP Switch Statement

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:


Syntax if Statement:

<?php
if (condition) {
code to be executed if condition is true;
}
?>

Syntax if...else Statement:

<?php
if (condition) {
code to be executed if condition is true;
} else {
code to be executed if condition is false;
}
?>

Syntax if...elseif...else Statement:

<?php
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.

Example (this is HTML - PHP editor, change text, values on this window)
<?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.

Example (this is HTML - PHP editor, change value of $numbr then click Execute)
<?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.

Example (this is HTML - change value of $numbr then click Execute)
<?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

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


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


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


Home
PHP Introduction
PHP Install
PHP Syntax
PHP Variables
PHP Echo and Print
PHP Data Types
PHP String Function
PHP Constants
PHP Operator Types
PHP If Else and Elseif
PHP Switch
PHP While Loops
PHP Loop For Do Foreach
PHP Array
Convert Array to String
PHP Function
PHP GET and POST
PHP Date/Time Functions
PHP Login
PHP Delete Element
PHP eregi_replace()
PHP mysql_query()
PHP Errors to Display
PHP Loop For Do Foreach

PHP forms
PHP Form Example
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


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


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


Error: Unable to connect to MySQL. Debugging errno: 1045 Debugging error: Access denied for user 'u142985959_ager'@'localhost' (using password: YES)