Tuesday, April 22, 2008

Use of === and !== operators in PHP

=== (identical)
$a === $b : TRUE if $a is equal to $b, and they are of the same type. (introduced in PHP 4)

!== (Not identical)
$a !== $b : TRUE if $a is not equal to $b, or they are not of the same type.

Example:
<?php
$a = "1"; //String
$b = 1; //Integer
if($a == $b)
echo "Equal<br />";
else
echo "Not Equal<br />";

if($a === $b)
echo "Identical<br />";
else
echo "Not Identical<br />";
?>

Output:
Equal
Not Identical


From: http://in.php.net/manual/en/language.operators.comparison.php

No comments: