为什么1234 =='1234 test'评估为true? [英] Why does 1234 == '1234 test' evaluate to true?
本文介绍了为什么1234 =='1234 test'评估为true?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
php == vs ===运算符
Possible Duplicate:
php == vs === operator
对于我确定的人来说,这是一个简单的答案.有人可以解释为什么此表达式的值为真吗?
An easy answer for someone I'm sure. Can someone explain why this expression evaluates to true?
(1234 == '1234 test')
推荐答案
因为您使用的是==(相似性)运算符,而PHP会将字符串强制为整数.
Because you are using the == (similarity) operator and PHP is coercing the string to an int.
要使用===(等于)运算符来解决该问题,该运算符不仅检查值是否相同,还检查数据类型是否相同,因此将不考虑"123"字符串和123 int相等.
To resolve it use the === (equality) operator, which checks not only if the value is the same, but also if the data type is the same, so "123" string and 123 int won't be considered equal.
这篇关于为什么1234 =='1234 test'评估为true?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文