PHP If..Else.. Statement

The conditional statements are used to take decision based on the different situations. You can use these statements in your code to make your decisions. Like other programming language, PHP also offers you to write these statements to perform different actions based on the results of a logical or comparative test conditions at execution time. PHP supports following decision making statements

PHP Conditional Statements…

Conditional statements are used to take actions based on different conditions. In PHP these are following conditional statements:

If Statement : Execute code when one condition is true, if condition is false than code will not be execute.

If.else statement : Execute codeĀ  if condition is true and another code if that condition is false

If .. elseif .. else statement : its use for more than two conditions..

Syntax:

<?php

if (condition) {
code to be executed if condition is true;
}

?>

Example:

<?php

$t = 50;
if ($t < 20) {
echo "Right Answer";
}

?>

Example:

<?php

$d = 10;

if ($d == 20)

echo "if condition is true";

elseif ($d == 10)

echo "elseif condition is true";

else

echo "elseif condition is true";

?>

Result: elseif condition is true



Coding Tag

Coding Tag always happy to serve you in Information Technology (IT). Learn HTML, CSS, Javascript, PHP, Android, Digital Marketing, Latest IT News and many more.

Leave a Reply

avatar
  Subscribe  
Notify of