Comparing a number with a string that contains number in PHP
<?php
if(12 == '12a1') // '12a1' will be converted into 12
{
echo 'True';
}
else
{
echo 'False';
}
// outputs True
if(12 == 'a121') // here 'a121' will be converted into 0, because of non-numerical character up front
{
echo 'True';
}
else
{
echo 'False';
}
// outputs False
if(12.5 == '12.5a') // here '12.5a' will be converted into 12.5
{
echo 'True';
}
else
{
echo 'False';
}
// outputs True
?>
if(12 == '12a1') // '12a1' will be converted into 12
{
echo 'True';
}
else
{
echo 'False';
}
// outputs True
if(12 == 'a121') // here 'a121' will be converted into 0, because of non-numerical character up front
{
echo 'True';
}
else
{
echo 'False';
}
// outputs False
if(12.5 == '12.5a') // here '12.5a' will be converted into 12.5
{
echo 'True';
}
else
{
echo 'False';
}
// outputs True
?>
Comments
Post a Comment