PHP if…else Statement

In php if..else statement we are asking php to verify the if statement and if it true echo the given outcome. or if the statement is false then use the next else statement to render the outcome. By using this you are verifying the statement and assuring the use will get some message display in both the condition.

The true value will generate the positive outcome that you have thought to render and in false value, you show the message of the false outcome.

Example:

[php]<?php
$t = "25";

if ($t == "20") {
echo "Have a good day!";
} else {
echo "Have a good night!";
}
?>[/php]

In the above example we are asking php script to check the variable, then move to the if statement to check the given condition. We are asking php to check the variable $t is equal to 25. If the condition matches present the echo statement “Have a good day“.

If the variable doesn’t match then use the else statement to output the echo statement that says “Have a good night“.

In our case, the $t variable is not matching with the variable statement so the code will show below message.

Have a good night!

Related Posts

Leave a Reply