Comparing String to Integer gives strange results

后端 未结 5 1778
北恋
北恋 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:06

    From the PHP manual:

    String conversion to numbers

    When a string is evaluated in a numeric context, the resulting value and type are determined as follows.

    The string will be evaluated as a float if it contains any of the characters '.', 'e', or 'E'. Otherwise, it will be evaluated as an integer.

    The value is given by the initial portion of the string. If the string starts with valid numeric data, this will be the value used. Otherwise, the value will be 0 (zero). Valid numeric data is an optional sign, followed by one or more digits (optionally containing a decimal point), followed by an optional exponent. The exponent is an 'e' or 'E' followed by one or more digits.

提交回复
热议问题