What are relational operators? Explain with suitable example.

This question are relatited by fronted web. I want to this question for education of education. some one reply this question answer. I am waiting for your answer.

1 Answer

➤In PHP, relational operators are used to compare values and determine the relationship between them. Here are the common relational operators in PHP:-

 Equal to ('=='): Checks if two values are equal.
$a = 5;
$b = 5;
if ($a == $b) {
echo "$a is equal to $b"; // This will be printed
}
 Identical ('==='): Checks if two values are equal and of the same data type.
$num = 5;
$str = "5";
if ($num === $str) { echo "$num is identical to $str"; // This will not be printed
} else {
echo "$num is not identical to $str"; // This will be printed
}
 Not equal to ('!='): Checks if two values are not equal.
$x = 10;
$y = 20;
if ($x != $y) {
echo "$x is not equal to $y"; // This will be printed
}

 Not Identical ('!=='): Checks if two values are not equal or not of the
same data type.
$num = 5;
$str = "5":
if ($num == $str) {
echo "Snum is not identical to $str"; // This will be printed
} else {
echo "Snum is identical to $str"; // This will not be printed
}
Greater than ('>'): Checks if the left operand is greater than the right
operand.
$m=8;
$n=3;
if ($m> $n) {
echo "$m is greater than $n: // This will be printed.
}
Less than ('<'): Checks if the left operand is less than the right operand.
Sp=15;
Sq=20;
if (Sp < $q) !
echo "Sp is less than $q"; // This will be printed
} 


Greater than or equal to ('>='): Checks if the left operand is greater than or equal to the right operand.
Salpha = 12; $beta = 10;
if (Salpha >= $beta) (
echo "Salpha is greater than or equal to Sbeta"; // This will be printed
}
 Less than or equal to ('<='): Checks if the left operand is less than or equal to the right operand.
Sgamma = 25;
$delta = 30;
if ($gamma <= $delta) {
echo "$gamma is less than or equal to $delta"; // This will be
printed }

We use cookies to enhance your experience, to provide social media features and to analyse our traffic. By continuing to browse, you agree to our Privacy Policy.