Home  >  Article  >  Backend Development  >  较长数字 字符串 的比较有关问题

较长数字 字符串 的比较有关问题

WBOY
WBOYOriginal
2016-06-13 11:42:58846browse

较长数字 字符串 的比较问题

本帖最后由 anyilaoliu 于 2013-12-13 15:04:43 编辑 如题 
遇到这样的问题

<br />$a = "222111565652521142";<br />		$b = "222111565652521139";<br />		$c = 222111565652521142;<br />		$d = 222111565652521139;<br /><br />		var_dump($a);<br />		echo "<br/>";<br />		var_dump($b);<br />		echo "<br/>";<br />		var_dump($c);<br />		echo "<br/>";<br />		var_dump($d);<br />		echo "<br/>";<br /><br />		if ($a == $b) {<br />			echo 3;<br />		}else{<br />			echo 31;<br />		}<br />		echo "<br/>";<br /><br />		if ($c == $d) {<br />			echo 4;<br />		}else{<br />			echo 41;<br />		}<br />		echo "<br/>";<br />


结果是


<br /><br /><br />string '222111565652521142' (length=18)<br /><br /><br />string '222111565652521139' (length=18)<br /><br /><br />float 2.2211156565252E+17<br /><br /><br />float 2.2211156565252E+17<br /><br /><br /><br />31<br />4<br />


问题来了,第二种情况 如何进行两者的比较

问题二: 从数据库中读出来的这两组数字,var_dump后显示是string(18)  但是比较结果和上边的例子恰好相反,两个string的 比较相等 也通过了.

求解
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