PHP string == comparison operator side effects_PHP tutorial

WBOY
Release: 2016-07-21 15:43:17
Original
899 people have browsed it

Copy code The code is as follows:

$a = '212345678912000005';
$b = '212345678912000001';
var_dump ($a == $b);

The output of this code is bool(true), which means that this judgment will conclude that the two are equal. Similar characteristics are in the in_array() function When the three parameters are false or not set. The reason is to first determine whether the string is a number, then convert it to long or double (C language data type) and then determine - use zendi_smart_strcmp. However, the comments in the source code say that the statement considers overflow In the case of {
/* Both values ​​overflowed and have the same sign,
* so a numeric comparison would be inaccurate */ goto string_cmp; }
dval1 and dval2 They are the values ​​after converting the two strings into double types. But why is this still the case? Maybe this judgment is not correct. Let’s study further...

Solution, use three equal signs "== ="Instead of two equal signs "==", the in_array() function sets the third parameter to true: in_array('val', $array, true).



http://www.bkjia.com/PHPjc/320772.html
www.bkjia.com

true
http: //www.bkjia.com/PHPjc/320772.html

TechArticleCopy the code as follows: $a = '212345678912000005'; $b = '212345678912000001'; var_dump($a = = $b); The output of this code is bool(true), which means that this judgment will lead to the conclusion that the two are consistent...
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