Comparison Operator:
It is another kind of operator supported by PHP, with this operator you can compare two variables, whether the variables are equal or not, which variable is larger, which one is smaller etc.
PHP provides a special type of operator (= = =) which compares two variables and their data type .e.g. if we compare "23" (string data type) and 23 (integer data type) with = = operator, the result would be true, but (= = =) will display false because of the dissimilarity of data type.
Another way of comparison could be done by ternary operator (? :), in this operator we place the condition section before (?) and the true section after (?) and the false portion after (:).
Example:
<?
$a
=12;$b
=12;var_dump (
$a==$b);echo "<br/>";var_dump (
$a===$b);echo "<br/>";var_dump (
$a!=$b);echo "<br/>";var_dump (
$a<>$b);echo "<br/>";var_dump (
$a<$b);echo "<br/>";var_dump (
$a>$b);echo "<br/>";var_dump (
$a<=$b);echo "<br/>";var_dump (
$a>=$b);echo "<br/>";?>
OOutput:
bool(true)
bool(true)
bool(false)
bool(false)
bool(false)
bool(false)
bool(true)
bool(true)
Example:
<?php
var_dump(
"23"==23);echo
"<br/>";var_dump(
"23"===23);Output:
bool(true)
bool(false)
Example:
<?php
$a
=23;$b
=45;$c
=($a>$b)?$a:$b;echo
"Larger number is= ".$c;Output:
Larger number is= 45
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.