Elseif Conditions PHP Essential Training

Elseif Conditions PHP Essential Training

PHP

Elseif Conditions PHP Essential Training

In our previous lesson we've take a look at how to work with if and else condition. In this lesson we're gonna teach you the next level in if conditions. Here it is one of the important testing condition if we work with some bigger logical expressions. This is a concept of check condition of a expression if it is true then execute a set of statements as like as an normal if else condition. If doesn't true then the else if is checks another set of condition and if that condition is true then that will execute a set of conditions.
This set of instructions we can write any number of times until getting a correct set of statements. Lets see how the else if is differentiate with elseif conditions.
if (condition) {
# code...
}
The above syntax will gives you a clear idea about how the if is working. Lets see with the example.
<?php
// Declare the normal variables and assign the variables
$a = 45;
$b = 40;
// Put the if condition here for check the variable values which one is big
if ($a > $b) {
// Here it displays "A is Larger than B" if the value of $a is greater than value of $b.
echo "A is Larger than B: " . $a . "<br />";
}
Elseif Conditions PHP Essential Training
These are all the normal if condition functions like we saw in our last lesson. This will be a reminder for you to prepare for the next step we move to the elseif conditions PHP Essential Training. The base of this else if condition is very simple, but gives you large options to perform. So in else if we first check a single condition, whether it is true then it'll runs a set of statements what you wants. Or else you if it is not true then we want to check another condition to perform another different set of statements.
In elseif conditions PHP essential training we can use many if conditions for a single statement on a certain application. It gives us a opportunity to present a output after checking many conditions. The best example for this if and elseif conditions is the online shopping site product filters.
The following example will gives you a clear idea about the elseif conditions php essential training
<?php
// Initialize the variables with values
$a = 5;
$b = 40;
// Check whether the value of $a is greater than value of $b
if ($a > $b) {
// If it is true then the following will be the display the program is ends here
echo "A is Larger than B <br />";
}
// If suppose the above condition is not true then it checks whether the value of $a is equals to value of $b
elseif ($a == $b) {
// Then the following statement will be executed
echo "A is equal to B <br />";
}
// In sometime the above two conditions are not true then we wants to notify are some other alternate functions to perform like the values or not correct. Then we go for else functions
else {
// All the above conditions are not true then it'll execute the following statements
$a = $b + 1;
echo 'Value of $a: ' . $a . "<br />";
}
?>
Elseif Conditions PHP Essential Training

Elseif Conditions PHP Essential Training

The above condition is shows the output of the elseif statement. We can change the values of $a and $b and check what will be the result.
<?php
// Initialize the variables with values
$a = 43;
$b = 25;
// Check whether the value of $a is greater than value of $b
if ($a > $b) {
// If it is true then the following will be the display the program is ends here
echo "A is Larger than B <br />";
}
// If suppose the above condition is not true then it checks whether the value of $a is equals to value of $b
elseif ($a == $b) {
// Then the following statement will be executed
echo "A is equal to B <br />";
}
// In sometime the above two conditions are not true then we wants to notify are some other alternate functions to perform like the values or not correct. Then we go for else functions
else {
// All the above conditions are not true then it'll execute the following statements
$a = $b + 1;
echo 'Value of $a: ' . $a . "<br />";
}
?>
Elseif Conditions PHP Essential Training
The above examples will gives you an clear knowledge about the "if", "else", and "elseif" functions. The next lesson is about how to work with logical operators like AND, OR operators in the if and else conditions.
Download the source code for Elseif conditions PHP Essential Training from here.

Leave a Reply