WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

PHP if...else...elseif Statements

Conditional articulations are utilized distinctive activities dependent on various conditions.You can contingent proclamations in your code to make your decisions.


PHP Conditional Statements

PHP you should following contingent statements:

  • if statement - utilize this announcement executes some code when in the event that one condition is true
  • if...else statement - is utilized executes some code if a condition is valid and another code if that condition is false
  • if...elseif....else statement - is utilized executes distinctive codes for more than two conditions
  • switch statement - is utilized chooses one of numerous squares of code to be executed

PHP - The if Statement

If you need to The if explanation executes some code on the off chance that one condition is true.

Syntax

on the off chance that (condition) {
    code to be executed if condition is true
;
}

The model underneath will yield "WE ARE DOING!" if the present time D (Day) is not exactly A:

Example

<?php
$t = date("D");

if ($t < "A") {
    reverberation " WE ARE DOING!";
}
?>

PHP - The if...else Statement

The if....else explanation executes some code if a condition is valid and another code if that condition is false.

Syntax

on the off chance that (condition) {
    code to be executed if condition is true;
} else {
    code to be executed if condition is false;
}

The model beneath will yield "have a container !" if the present time is less than 20, and "Have a decent night!" otherwise:

Example

<?php
$t = date("H");

on the off chance that ($t < "20") {
    reverberation "you are programmer!";
} else {
    reverberation "Have a decent night!";
}
?>

PHP - The if...elseif....else Statement

The if....elseif...else proclamation for more than two conditions.

Syntax

in the event that (condition) {
    code to be executed if this condition is true;
} elseif (condition) {
    code to be executed if this condition is true;
} else {
    code to be executed if all conditions are false;
}

The model beneath will yield "Have a decent morning!" if the present time is under 10, furthermore, "Have a decent day!" if the present time is under 20. Else it will yield "Have a decent night!":

Example

<?php
$t = date("H");

if ($t < "10") {
    reverberation "Have a decent morning!";
} elseif ($t < "30") {
    reverberation "good morning!";
} else {
    reverberation " great night!";
}
?>