'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

Download Image from URL and Upload it
Ok, I have been googling for the last 1/2 hour trying to figure this out, Most likely I'm just not s

j1inmis Ouput layout changes
Hi,

Can anybody tell how can j1inmis output layout can be changed so that vendor names ge

How to store checkbox array in a session, and then be able to add to it?
I'm trying to store an array of checkbox values into a session array, sort of like a shopping cart,

Weird MySQL error, why am I recieving this?
PHP Code:


<?php require "global_settings.php"; ?>
<titl

form submit at godaddy?
Trying to test form submission at GoDaddy and it does not seem to work. Here's the page...

h

php multiple action on submit
I have a form which says:

<form enctype='multipart/form-data' method='post' action='pr

Allegro crashes when running load_bitmap. Why?
I can not get Allegro to load any BMP images. Here is a section of test code. The picture is in the

get multiple rows
Hi I want to get multiple rows from a db

I am using this for the db query
Code: public

mysql_real_escape_string
Let me preface this that I am very much a PHP noob, but I have some SQL training (not necessarily My

foreach loop, assistance request
I would like some guidance on the usage of foreach as I try to parse through a large database and wh

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