Understanding PHP Type Coercion

前端 未结 4 666
梦谈多话
梦谈多话 2020-12-03 15:34

I saw this small piece of code that is evading my understanding:



        
4条回答
  •  心在旅途
    2020-12-03 16:19

    It is not really an answer, but if you try:

    $a = '0e4620974319065090195629887368549';
    $b = '0e8304004519934940580242199033918';
    echo floatval($a) . '
    ' . floatval($b);var_dump($a == $b);

    You get:

    0

    0

    bool(true)

    Now, if you try:

    $a = '0e4620974319065090195629887368549';
    $b = '1e8304004519934940580242199033918';
    echo floatval($a) . '
    ' . floatval($b);var_dump($a == $b);

    You get:

    0

    INF

    bool(false)

    My guess is that PHP converts the strings to floats and gives comparison result using the floats obtained, which are not correct anyway, but that is another story.

提交回复
热议问题