Mostly when writing codes, we only want to execute some actions for certain conditions. In PHP, we can use a conditional statement to execute a code only if the condition is meet.

Conditional Statements:

if statement – executes a code only if a specified condition is true
if…else statement – executes a code only if a condition is true and other code if the condition is not true
if…elseif….else statement – execute a code only if one of conditions is true

if Statement

If statement will execute a code if a specified condition is true.

Syntax: if(condition){ code to execute if condition is true }

Example


<?php
$name = 'Bryan';
if($name == 'Bryan'){
	echo 'My name is Bryan.';
}
?>

if…else Statement

if…else statement will execute a code if a specified condition is true and other code if the condition is false.

Syntax:
if(condition){
code to execute if condition is true
}else{
code to execute if condition is false
}

Example


<?php
$name = 'Bryan';
if($name == 'Bryan'){
	echo 'My name is Bryan.';
}else{
	echo 'I am not Bryan';
}
?>

if…elseif….else statement

if…elseif….else statement will execute a code only if one of the conditions is true.

Syntax:
if(condition 1){
code to be executed if condition 1 is true
}elseif(condition 2){
code to be executed if condition 2 is true
}else{
code to be executed if none of the conditions is true
}

Example


<?php
$name = 'Bryan';
if($name == 'Bryan'){
	echo 'My name is Bryan.';
}elseif($name == 'Petter'){
	echo 'My name is Petter';
}else{
	echo 'I am not Bryan nor Petter';
}
?>

How to take Cialis it seems to me that would already be time to cease to discuss this question. As I already answered it not once. Have it in a look. You shouldn’t worry! All deer go south when they are called by homesickness. Are turned and lie on snow till some hours.