'210010106140040100' == '210010106140040101'


Posted on 16th Feb 2014 07:03 pm by admin

Debugging this simple line of a PHP script

Code: if($a == $b){ }
I've found that with value of
$a = '210010106140040100' (type = string)
$b = '210010106140040101' (type = string)

the result of the comparison is TRUE

the same if i compare 2 integer

$a = 210010106140040100 (type = int)
$b = 210010106140040101 (type = int)

$a == $b ( true )

If I use the === operator

'210010106140040100' === '210010106140040101' (comparison of strings: result is FALSE)
210010106140040100 === 210010106140040101 (comparison of numbers: result is TRUE)

I think it could be caused by the fact that the string is 'like' integer, but exceed the standard size of integer number.
But the final result remain a mistery for me: I've tested some others 'big' numbers and I've found for example:

18014398509481980==18014398509481981 (true) !!!!
18014398509481982==18014398509481981 (false) !!!!

In my specific script i can handle this specific comparison using the === operator, because i can assume that the variable are string.

But i'd like to know why this happen, and i'd appreciate suggestions about how to efficiently compare 'big' integers.

Thanks!

I use PHP 5.2 with IIS

No comments posted yet

Your Answer:

Login to answer
199 Like 53 Dislike
Previous forums Next forums
Other forums

update the selected existing records of database
Hi frndz,
I am new to php and get stuck....

Edit.php > Update.php > Updatea

"GROUP BY" in arrays
Well i'm looking to do something i usually could do easily using COUNT and GROUP BY if it was a sql

Alterar a hora do servidor
Se alguém souber, ajude-me a adicionar 6 horas, obrigado
<tr>
&

Coefficient of a Restitution Hints
Hello. I was wondering if anyone can give me hints on how to write this program...

The coeffi

Querying info from one table based on info in another
Hi, I am currently trying to make a part for my user driven website where one user can subscribe to

PHP File Upload Problem
Hi, I have written a very simple file upload script but it fails for reasons I can't explain. Hope

PO Release Strategy Issue
Hi Experts,

I am facing an issue related to PO release strategy. The details are-
<

Create multiple (n) arrays
Hi there,

I have the following need:

I have 2 arrays (coming from a databases)

Disabling SAP menu
How do I disable SAP menu for all the users and just restrict them to User Menu in SAP ECC 6.0?

help with Get_
ok some how this is not working i am not sure what i am doing wrong here but what this does is when

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash