'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
Did you know?Explore Trending and Topic pages for more stories like this.
$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

Small problem with image resize script
Hi!

I am a little bit new to php and I have an issue installing an image resize script I down

generating random codes
Hi guys n gals,

I have a requirement to generate 250,000 unique codes...

These codes a

PHP webpage & array print issue
I have this code running, and it works perfectly … however, see my bottom bit about what I see

I need help with formatting date from mysql! with php!
Hello guys

*Note: this is a php question not MySQL question, please do not move it to mysql s

Count number of records in all the tables with a querry URGENT PLEASE...
I downloaded ORACLE 9I DATA DUMP into my comp. There are number of tables. I need to find out the

PHP Array quick help
I need

$_SESSION{'username'} to be like this:


if $_SESSION['username'] = "gay

need help in update query
i create a form for update. there are 8 columns in my mysql table. on my main page all the data is r

How to show more than 1 users with this code...
Hello,
i have a table that shows users only if I, as Administrator, want to be shown. But its sho

disable all input buttons
Hello Friends,

suppose i do have a file ( file.php ) has a submit button

Code: [Sele

Update not working ... please help
Hi,

I am trying to update a row using an edit form by passing id of the row .. but it is not

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