If else functions PHP Essential Training

If Else Functions PHP Essential Training

PHP

If Else Functions PHP Essential Training

After finishing all the previous lessons in our previous PHP essential training definitely you'll get an basic idea about how the PHP and its functionalities are working. And now we're gonna learn the real essences of the PHP language. If else functions PHP Essential Training is an lesson to begin the logical and technical stuffs in PHP.
When ever use the word "if" then we know there is an else part is available. So If else functions PHP Essential training is talks about the conditions. The if is checks a certain condition and performs some code whether the if condition is true. You may can ask what is the else part. Obviously we have a alternate solution for a problem, in real life as well as in a coding world. That's why the PHP also has the else part, however the if condition is not true then we will go for the else part and it'll performs the another set of code to provide an alternate solution.
Lets do the following example to test how the if else functions PHP essential training is works on real time examples. Build your default project settings like open xampp and run the necessary files. Start the coding and check how it works in a basic way.The following is the syntax for the if 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 = 55;
$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 />";
}
If Else Functions PHP Essential Training
The above is a very basic only if condition checking example. But the main purpose of this concept is check a condition and execute a code if it is not working then go for the next one. Lets do that in our following example.
<?php
// Declare the normal variables and assign the variables
$a = 5;
$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 <br />";
}
// Suppose the value of $a is not greater than $b then the alternate else is executes here.
else {
echo "Before Change: " . $a . "<br />";
$a = $b + 1;
echo "After Change: " . $a . "<br />";

// Perform any kind of alternate operation you want to execute inside the else
$a = $b + 1;
// Just display the output what we got in our else part
echo "After Change: " . $a . "<br />";
}
?>
If Else Functions PHP Essential Training
We hope the above lesson will gives you a basic idea about how to work with if and else conditions. Our next lesson will discuss about the else if conditions.
Download the source code for If Else Functions PHP Essential Training from here.

Leave a Reply