You are currently viewing What is PHP if else Statement | Explained
  • Post category:PHP

What is PHP if else Statement | Explained

What is PHP if else Statement

In this article, we will see what is php if else statement.

if else statement

It executes true part; if the conditional expression inside the parenthesis evaluates to true. else statement executes the false part.

Syntax:

if(conditional expression)
{
statements; //true part
}
else
{
statements; //false part
}

OR

if(conditional expression):
statements; //true part
else:
statements; //false part
endif;

Note: if the true part gets executed then the false part is not executed, vice versa.

Examples

<?php
$a = 20;
if($a == 10)
{
echo " a is equal to 10";
}
else
{ echo " a is not equal to 10" };
?>
// output : a is not equal to 10

OR

<?php
$a = 10;
if($a == 10) :
echo " a is equal to 10";
else:
echo " a is not equal to 10";
?>

// output : a is equal to 10

Leave a Reply