|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30000 in_array returns the wrong result with long strings
Submitted: 2004-09-06 17:02 UTC Modified: 2007-07-09 13:34 UTC
Avg. Score:4.5 ± 0.9
Reproduced:2 of 4 (50.0%)
Same Version:1 (50.0%)
Same OS:2 (100.0%)
From: rcnetto at yahoo dot com Assigned:
Status: Wont fix Package: Arrays related
PHP Version: 5.0.1 OS: Linux - Suse 9.1
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: rcnetto at yahoo dot com
New email:
PHP Version: OS:


 [2004-09-06 17:02 UTC] rcnetto at yahoo dot com
I tried to check if a value existed in an array, but in_array did not return what I expected when I'm dealing with large strings (18 chars or longer).

I have PHP 5.0.1 compiled with Apache 2.0.50 and DBG v2.11.26 running;

Reproduce code:
    $needle = '123456789012345671';
    $arrayA = array('123456789012345672'); // check number is different
    var_dump(in_array($needle, $arrayA)); // the correct output is FALSE, but TRUE is printed

Expected result:

OBS: $needle does not exists in $arrayA (last number is different), that's why it should return FALSE.

Actual result:

Notes: when the value of the variables are letters, in_array works fine with the same quantity of chars.
    $needle = 'abcdefghijklmnopqr1';
    $arrayA = array('abcdefghijklmnopqr2'); // last char is different
    var_dump(in_array($needle, $arrayA));


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-10-06 01:57 UTC]
Numeric strings get converted to integers when used as array keys. Because ints are limited to 32 bits (on x86) they end up being 0 on very large numbers.
 [2004-10-06 13:40 UTC] rcnetto at yahoo dot com
Interesting,... using the strict parameter will force in_array to check types (or not converting to int??). Then the result will be ok.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 13 07:01:29 2024 UTC