<?PHP $a = 3; if ($a != 4) {...}//True if ($a <> 4) {...}//True if ($a == "3") {...} //True $a = array("2","3.4","5.342","0","3","-5","6.3"); $b = array(2,3.4,5.342,0,3,-5,6.3); if ($a == $b) echo "True"; else echo "False"; //True ?>
The operators can be used to compare arrays.
<?PHP $a = array("2","3.4","5.342","0","3","-5","6.3"); $b = array(2,3.4,5.342,0,3,-5,6.3); if ($a == $b) echo "True"; else echo "False"; //True ?>
<?PHP $a = 3; if ($a == "3") {...}//True if ($a === "3") {...}//False if ($a !== "3") {...}//True ?>
<?PHP $a = NULL; if ($a == NULL) echo "True"; //True if ($a === NULL) echo "True"; //True if (is_null($a)) echo "True"; //True $a =''; if ($a == NULL) echo "True"; else echo "False1"; //True if ($a === NULL) echo "True"; else echo "False2"; //False if (is_null($a)) echo "True"; else echo "False3"; //False ?>
When the operator is not type sensitive, 0, FALSE, empty string will be treated as equal to each other.
<?PHP $a="";$b=0; $c=FALSE; if ($a == $b) echo "True"; else echo "False"; //True if ($a === $b) echo "True"; else echo "False"; //False if ($c == $b) echo "True"; else echo "False"; //True if ($c == $b) echo "True"; else echo "False"; //False $a = NULL; $b = 4/0; if ($a == $b) echo "True"; else echo "False"; //True ?>
<?PHP echo 2.1 <=> 5; //-1 echo 2.1 <=> 2.1; //0 echo 9 <=> 4; //1 ?>
Following is the list of all comparison operators in PHP.