if statements works like this
if (condition is true)
{
Execute code;
}
i.e. id statements only executes specified code if the condition is true otherwise code is completely ignored and is not executed.
Example
$int i= 4; If (i < 5) { echo "value of i is greater then 5"; }
We use the various operators to create condition in if statements.
Using > and < operators
Greater than and less than operators are commonly used operators.
You can compare constant, constant with variables and variables.
See the Example:
If (5 < 10) { echo "5 is less than ten"; }
Using == and === operators
Equality operator is used for checking the exact match condition, see this:
$int i= 5; If (i == 5) { echo "value of i is 5"; } else { echo "value of i is not 5"; }
And === operator evaluates to true only if values are equal and data types of the values are also equal, see the example:
$int i= 5; $int j= 5; If (i === j) { echo "both variables are equal"; }
The != and <> operators
Inequality is the reverse of the equality operator(==). See the following:
$int i= 5; If (i!= 7) { echo "value of i is not 7"; }
Or we can use also <> operator for getting the same result:
$int i= 5; If (i <> 7) { echo "value of i is not 7"; }