Home > php教程 > php手册 > PHP 坑之 ==

PHP 坑之 ==

WBOY
Release: 2016-06-06 20:14:08
Original
1218 people have browsed it

PHP 中 “== ”判断两个变量是否相等的时候会进行自动的类型转换。今天Tom Hessman,在twitter上提到了PHP用==做判断的时候一种极端情况(很坑)。 //ok it return truevar_dumpmd5'240610708' == md5'QNKCDZO';var_dumpmd5'240610708';//string(32) "0e4620

PHP 中 “== ”判断两个变量是否相等的时候会进行自动的类型转换。今天Tom Hessman,在twitter上提到了PHP用==做判断的时候一种极端情况(很坑)。

//ok it return true
var_dump(md5('240610708') == md5('QNKCDZO'));
var_dump(md5('240610708'));
//string(32) "0e462097431906509019562988736854"
var_dump(md5('QNKCDZO'));
string(32) "0e830400451993494058024219903391"
Copy after login

PHP把两个字符串转换成科学计数来比较了。。。

严谨比较还是用 === 这个吧


评论| 作者: tomheng 85159e08d5f1f50d244825cb03e92c65
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template