PHP if Condition
In this article, we will see about PHP if condition. Before learning if compulsory know about PHP conditional statements.
PHP Conditional statements
The conditional/selection statements help us to execute a set of statements based on the result of a given conditional expression. There are four types of a conditional statement available in PHP, they are:
- if,
- if else,
- else if ladder,
- switch case
if statement
It executes the true part; if the conditional expression inside the parenthesis evaluates to true.
Syntax:
if(conditional expression)
{
statements; //true part
}
OR
if(conditional expression) :
statements
//true part
endif;
Example
<?php
$a=10;
if($a==10)
{
echo "a is equal to 10";
}
OR
if($a==10):
echo "a is equal to 10";
endif;
?>