Type casting and Comparison with Loose Operator “==”

前端 未结 7 2289
暖寄归人
暖寄归人 2020-12-10 16:58

I have a problem baffling me terribly. I noticed this before but didn\'t give it any heed until today. I was trying to write my own check for integer strings. I know of

7条回答
  •  伪装坚强ぢ
    2020-12-10 17:09

    According to php.net http://php.net/manual/en/language.operators.comparison.php:

    var_dump(0 == "a"); // 0 == 0 -> true
    

    So, I think it is juggling the types, and actually casting both sides to int. Then comparing either the sum of the ascii values or the ascii values of each respective index in the string.

提交回复
热议问题