Comparing String to Integer gives strange results

后端 未结 5 1828
北恋
北恋 2020-11-22 16:41

I\'m really confused as to why this operation works. Can someone explain it?

$test1 = \"d85d1d81b25614a3504a3d5601a9cb2e\";
$test2 = \"3581169b064f71be1630b         


        
5条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 17:13

    I've been using some conversions and comparisons to test if a numeric string is a number:

    $test1="19de6a91d2ca9d91721d82f1bd8102b6";
       echo (float)$test1==$test1; //TRUE
       echo is_float($test1); //FALSE
    
       //Converting the string to float and then converting it to string and compare will do the trick 
       echo (string)((float)$test1)==(string)$test1; //FALSE
    
    
    $test2="5.66";
       echo (float)$test2==$test2; //TRUE
    
       //Testing the numeric string using `is_float` wont give the expected result
       echo is_float($test2); //FALSE
    
       echo (string)((float)$test2)==(string)$test2; //TRUE
    

提交回复
热议问题