Sunday 7 February 2010

take care of php loose comparisons

php has both strict comparison and loose comparison.
see the example.
if("6x"==6)
{
echo "surprice";
}
else
{
echo "i am aware.";
}
in a comparison, if either side has number then both the parameters will be converted to number and will check 6==6, so the output will be "surprice".

In these case, checking with === will work as usual.
eg: if("6x"===6)