php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66166 in_array() 返回的判断结果是错误的
Submitted: 2013-11-25 11:52 UTC Modified: 2013-11-25 12:26 UTC
From: 290315384 at qq dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: master-Git-2013-11-25 (Git) OS: win7
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: 290315384 at qq dot com
New email:
PHP Version: OS:

 

 [2013-11-25 11:52 UTC] 290315384 at qq dot com
Description:
------------
---
From manual page: http://www.php.net/function.in-array
---

PHP version:5.3.13
Package affected:

Test script:
---------------
<?php
 $arr = array ('22727824922116425');
var_dump(in_array('22727824922116421',$arr));	//true
var_dump(in_array('22727824922116422',$arr));	//true
//......
var_dump(in_array('22727824922116426',$arr));	//true
var_dump(in_array('22727824922116427',$arr));	//true
var_dump(in_array('22727824922116422',$arr,true));	//false

 $arr = array (22727824922116425);
var_dump(in_array(22727824922116422,$arr));		//true
var_dump(in_array(22727824922116422,$arr,true));//true
?>



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-11-25 12:26 UTC] bwoebi@php.net
-Status: Open +Status: Not a bug
 [2013-11-25 12:26 UTC] bwoebi@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://www.floating-point-gui.de/

Thank you for your interest in PHP.

Numeric strings are, if the third parameter ($strict) is not set, compared numerically.

Too big integers are already casted to float before they are passed to the function in_array.

But due to floating point imprecision, it has the same binary representation, so it's true even with strict parameter.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 23:01:29 2024 UTC