Why md5('240610708') is equal to md5('QNKCDZO')? [duplicate]

和自甴很熟 提交于 2019-12-20 09:49:31

问题


var_dump(md5('240610708') == md5('QNKCDZO'));

Output:

bool(true)

Example: http://3v4l.org/2vrMi


回答1:


md5('240610708') 's result is 0e462097431906509019562988736854.

md5('QNKCDZO') 's result is 0e830400451993494058024219903391.

They are both float number format strings (numerical strings), and if you use == in php, when compare a number with a string or the comparison involves numerical strings, then each string is converted to a number and the comparison performed numerically.

Both of the strings are converted to 0 when compared with ==, if you want to compare them as string, remember to use ===(strict comparison) instead.

See: PHP expresses two different strings to be the same




回答2:


You need to use the type-sensitive comparison operator ===.

The hashes evaluate to 0e462097431906509019562988736854 and 0e830400451993494058024219903391, respectively. When you use ==, each is converted to a numeric representation because of the e (scientific notation), so they each become 0. 0 == 0 is true.

On the other hand, this:

md5('240610708') === md5('QNKCDZO')

returns false because the string values are different. === forces type-sensitive comparison.



来源:https://stackoverflow.com/questions/22140204/why-md5240610708-is-equal-to-md5qnkcdzo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!