这两种写法等价吗

WBOY
Release: 2016-06-23 13:34:16
Original
1127 people have browsed it

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  含义变了,变成判断第一个字符是否为“:”

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
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!