'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

Set Categories
I am creating a submission form for somebody to come in and submit products. These products are sep

Printer configuration
Hi All,
Suppose one of the user deleted the printer settings unfortunatly ,then what is the pro

Socket problem
Hello,

Earlier I posted about my problem with my socket script. It took up to 100% CPU usage.

Registration
ok so i have a site where people can register and login which works now thanks to someone on here th

DataTable Help Required
Hi all I am creating an app that utilises and MS Access back end and queries it quite a bit at vario

Display a default image
I am trying to display generic image for items that don't have one, but I can't get it to display.

Uploading/Downloading files stored in MySQL database
Hey all,

This problem just came up in my website and I'm having a hard time figuring out what

IF Statement & Two Tables With Different Echoes
I'm retrieving two tables in a single query using UNION ALL, like so:

Code: $query = "SE

2 decima places & How to reload my page
Hello There,

How do i put full-stop (.) after second figure from behind? ie if i have 123456

onClick='location.href=index.htm'> not working
Below is my code:

echo "<input type='button' value='redirect' onClick='location.h

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