php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #8409 in_array acting strange
Submitted: 2000-12-24 19:02 UTC Modified: 2001-01-07 18:32 UTC
From: anil at recoil dot org Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.0.4 OS: OpenBSD
Private report: No CVE-ID: None
 [2000-12-24 19:02 UTC] anil at recoil dot org
in_array() is acting very strange; here is the script I am using:

<?
$a = array('1.10','1.12.4.3','1.13.4.2');
var_dump($a);
if (in_array('1.1',$a)) echo '1.1 found without strict check';
if (in_array('1.1',$a, true)) echo '1.1 found with strict check';
?>

Output:

array(3) {
  [0]=>
  string(4) "1.10"
  [1]=>
  string(8) "1.12.4.3"
  [2]=>
  string(8) "1.13.4.2"
}
1.1 found without strict check

Now, '1.1' should never be found at all, since its not in the input string array, but it is found!

However, looking at the source code reveals an undocumented 'strict' argument, which when set to true, works correctly.

Two issues:

a) Could this extra parameter please be documented?

b) Why on earth does it match them as identical when it's not 'strict'?  Do they revert to being evaluated in an integer context (the only way I can think off that 1.10 and 1.1 would be equivalent)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-12-24 19:05 UTC] jmoore@php.net
changing bug type.. more suited to a docu problem.
 [2001-01-07 18:32 UTC] derick@php.net
Fixed in the documentation
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 08 22:01:31 2025 UTC