php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37403 Wrong key returned in array_search
Submitted: 2006-05-11 04:02 UTC Modified: 2006-05-11 16:55 UTC
From: jonataswalker at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.1.4 OS: Linux 2.6.13
Private report: No CVE-ID: None
 [2006-05-11 04:02 UTC] jonataswalker at gmail dot com
Description:
------------
Hi there,

I'd like some help. I've searched and found a similar question but no answer was given, so I need to ask same thing.

How can this be possible?

Reproduce code:
---------------
$array = array(3453453453453453453445345345,345345345345345346452,12345);
$key = array_search(345345345345345340300,$array,true);
if ($key === false) print "false";
else print var_dump($key);

Expected result:
----------------
false

Actual result:
--------------
int(1). Even changing last 4 digits in needle, I always get int(1).

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-05-11 06:50 UTC] derick@php.net
Floating point values have a limited precision. Hence a value might 
not have the same string representation after any processing. That also
includes writing a floating point value in your script and directly 
printing it without any mathematical operations.

If you would like to know more about "floats" and what IEEE
754 is read this:
http://docs.sun.com/source/806-3568/ncg_goldberg.html
 
Thank you for your interest in PHP.

.
 [2006-05-11 16:55 UTC] jonataswalker at gmail dot com
Well, the answer came very quick, thank you.
I read the recommended article but I didn't understand.
What would it be a solution?
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 23 01:00:02 2025 UTC