Doubts about php bit operations and shifts
PHP中文网
PHP中文网 2017-05-16 13:09:55
0
1
472

var_dump( (pack("C" , 1)<<1) ==pack("C" , 1) );
Why is it true

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(1)
phpcn_u1582

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template