关于php 位运算 移位的疑惑
PHP中文网
PHP中文网 2017-05-16 13:09:55
0
1
423

var_dump( (pack("C" , 1)<<1) ==pack("C" , 1) );
为什么是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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!