Home  >  Article  >  Backend Development  >  这两种写法等价吗

这两种写法等价吗

WBOY
WBOYOriginal
2016-06-23 13:34:161128browse

strpos($tplpath,':') !== false
strpos($tplpath,':') !== “ ”
或strpos($tplpath,':') !== NULL
或strpos($tplpath,':') !== 0
上在是不是都是等价的


回复讨论(解决方案)

不等价!
strpos 函数,成功返回从0算起的偏移量,不成功返回 false
!== 不等于,比较时连同数据类型一起比较

strpos($tplpath,':') !== false  这是正确的
strpos($tplpath,':') !== “ ”  strpos要么返回数值,要么返回逻辑假,不会返回字符类型,条件恒成立
strpos($tplpath,':') !== NULL  同上
strpos($tplpath,':') !== 0  含义变了,变成判断第一个字符是否为“:”

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn