php != 和 !== 的区别
2016-06-02 18:13
501 查看
==and
!=do not take into account the data type of the variables you compare. So these would all return true:
'0' == 0 false == 0 NULL == false
===and
!==do take into account the data type. That means comparing a string to a boolean willnever be true because they're of different types for example. These will all return false:
'0' === 0 false === 0 NULL === false
You should compare data types for functions that return values that could possibly be of ambiguous truthy/falsy value. A well-known example is
strpos():
// This returns 0 because F exists as the first character, but as my above example, // 0 could mean false, so using == or != would return an incorrect result var_dump(strpos('Foo', 'F') != false); // bool(false) var_dump(strpos('Foo', 'F') !== false); // bool(true), it exists so false isn't returned
转自: http://stackoverflow.com/questions/3641819/php-not-equal-to-and[/code]
相关文章推荐
- .Net Reflector或DotPeek反编译后无法查看设计器的解决方法
- matplotlib学习1
- php array_map与array_walk使用对比
- 编译vsftp出错的解决办法
- PHP手机,邮箱正则匹配
- PHP 数组排序二维或多维排序问题
- PHP数组
- 运用Thinkphp搭建简单留言板(附源码)-(上)
- php 打印小票模板
- [PHP源码阅读]strtolower和strtoupper函数
- php pdo 链接数据库
- PHP 操作文件没有权限:Permission denied
- Liunx 配置ftp服务器
- PHP 5.5 新特性关键字 yield
- php中die(),exit(),return的区别
- php 图片压缩 CURL 请求 删除文件夹目录和子文件 创建 目录
- 内网探测脚本(内网代理访问+内网端口扫描) [php+jsp] -------- 屌丝归档笔记
- 部署NTP服务器进行时间同步
- 敲php的日子
- thinkphp发送邮件 图文教程