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
?>

Comments

Popular posts from this blog

Timus 1209. 1, 10, 100, 1000... accepted solution in C

Timus Problem 1086. Cryptography Accepted Solution in C

Timus 1083. Factorials!!! Accepted Solution in C