var_dump( (pack("C" , 1)<<1) ==pack("C" , 1) );Why is it true
认证高级PHP讲师
When it comes to PHP comparison, type conversion1, pack("C", 1)<<1, the result is int(0)2, pack("C", 1), the result is string(" ")
In fact, it is simplified to the comparison of 0 == ""
PHP 在比较的时候,如果类型不相等,会进行类型转换 Here string("") will be converted to int type, that is, it will become int(0), so it returns true
PHP 在比较的时候,如果类型不相等,会进行类型转换
You have to judge strictly, you can use ===
===
var_dump( (pack("C" , 1)<<1) ===pack("C" , 1) ); The result is false
When it comes to PHP comparison, type conversion
1, pack("C", 1)<<1, the result is int(0)
2, pack("C", 1), the result is string(" ")
In fact, it is simplified to the comparison of 0 == ""
PHP 在比较的时候,如果类型不相等,会进行类型转换
Here string("") will be converted to int type, that is, it will become int(0), so it returns true
You have to judge strictly, you can use
===
var_dump( (pack("C" , 1)<<1) ===pack("C" , 1) ); The result is false