php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37235 in_array returns true for non-existing elements
Submitted: 2006-04-28 11:08 UTC Modified: 2006-04-28 12:13 UTC
From: hodacsi at mailbox dot hu Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.1.2 OS: Windows
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: hodacsi at mailbox dot hu
New email:
PHP Version: OS:

 

 [2006-04-28 11:08 UTC] hodacsi at mailbox dot hu
Description:
------------
The code speaks for itself: in_array founds a string in the array when it definitely should not.

The code is kept simple - I've also used variables and verified variable types with gettype, so it's _should not_ be a matter of using strict parameter.

Using the third 'strict' parameter it works as expected, even if it's definitely not a question of types. Tested under several PHP versions and platforms.

Reproduce code:
---------------
<?php

$ids = Array ( '+36901112222', 'xxxxx', 'zzzzz' );

echo in_array( ' 36901112222', $ids ) ? 'found' : 'not found';

?>

Expected result:
----------------
It should not find the string and should echo "not found".

Actual result:
--------------
"found"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-28 12:13 UTC] mike@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Set the third (optional) parameter to TRUE if you want to do strict checks, else type conversions (int in this case) will be performed.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 13:01:32 2025 UTC