Tuesday, 5 July 2011

Difference between == and ===

Everybody knows that the difference between = and ==. One equal sign is used when a variable is assigned a value and two are used
when their values are checked.Ok, so what is the use of ===. The following example illustrates it.
<?php
  $a=10;
  $b='10';
if($a==$b)
  echo 'Same';
if($a===$b)
  echo 'Not same';
?>
It will output 'same'. This is because == checks only for the value, not the datatype whereas === also checks for the datatype since $b='10', it is considered as character instead of integer.


No comments:

Post a Comment