如果(0 =='%')echo“WTF,Php,为什么你不能理智地比较事情? [英] if(0 == '%') echo "WTF, Php, why can't you compare things sanely?"

查看:151
本文介绍了如果(0 =='%')echo“WTF,Php,为什么你不能理智地比较事情?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是把一个疯狂的bug修改为这个问题的标题。
我相信有一个完全合理的解释为什么Php认为0 =='%'(或任何其他特殊字符,我想)。
我认为对StackOverflow有好的解释。

I just reduced a crazy bug to what's in the title of this question. I'm sure there's a Perfectly Reasonable Explanation for why Php thinks that 0 == '%' (or any other special character, I think). I thought it would be good to get that explanation on StackOverflow!

推荐答案

使用'==='精确,字面比较 - 值必须是相同的类型,也是等于)而不是'=='解决这个问题。 ==试图将%转换为数字,0是最好的。

Using '===' (for exact, literal comparison -- the values must be the same type and also equal) instead of '==' solves this problem. With '==' it's trying to cast '%' to a number and 0 is the best it can do.

这篇关于如果(0 =='%')echo“WTF,Php,为什么你不能理智地比较事情?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆