'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

How many users online in the last 24-hours using time()?
I'm fairly new to PHP. I have a MySQL table called 'users' and a field called 'loggedin' which is in

Paypal
Hi all,

I have an advanced basic knowledge of php

I want to try something new for a s

am I using this for loop correctly
Dear buddies!

Right now I am generating a report with some details for all the dealers.

How would I do "Users not logged in since *** delete them"
I know how I would set this up, and delete the user roughly.
I'll create a table called "Use

The type or namespace name 'ServiceModel' does not exist in the namespace 'System'
When I locally run the website, it works just fine, but when I uploaded it to the hosting environmen

Inserting Data into a MS Access DB using PHP.
As part of my uni course I am doing a placement at a company whom want me to create a client zone fo

PHP Surveys
I really would like some advice.

If you have a client come to you asking for a survey to be d

retrieving more than one max key from an array?
so i have an array of 20 numerical values (0-100) that i need to order from highest to lowest and th

Help with forum quoting?
Hi im working on a forum and I have alomost finished it but i want a user quote system like twitter

FAGL_FC_TRANSLATION FAS52 New GL ECC 6.0
Hello,

The new program for Translating GL Balances (FAS 52) gives the option to use diffe

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