'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
53
Other forums
Text Not Displaying Correctly With PHP:GD
I recently moved servers and since then I have noticed that one line of text is showing weirdly.
Using Windows message as a Handle
Hi,
I am writing one of my first multithreaded programs.
In one of the thread,
why is it over writing
Code: $filepaths[] = $_FILES['new_image'];
foreach ($filepaths as $filepath)
{
$imagename =
Adding to an Int row in db
Hi, i have a database which houses all of the users of my site. One of the columns is for points whi
strtotime issue
Hey all,
I'm playing around with some code, and basically the idea is:
Person changes
Must-Know Topics of PHP
Can you guys list the must-know topics of PHP. I am still a learner and I am trying to cover most of
Need help adding a timestamp to my filename/variable
Hello,
I'm kind of stupid when it comes to php and I need a tiny bit of help. I've got a f
PHP error on MySQL insert
I'm sure it's the simplest of issues, but I can't recall why this isn't working.
Code: [Selec
php problem?
I don't think I'm stupid, but maybe I am.
I am working on a sit for a friend I am try to put
Help with Contact Form
I have this Form on an html page and the associated code on page.php (below).
I keep getting the