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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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: Sun Dec 22 12:01:30 2024 UTC