php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65639 in_array unexpected result
Submitted: 2013-09-09 07:35 UTC Modified: 2013-09-09 08:35 UTC
From: sv3tli0 at bgspot dot eu Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.4.19 OS: Ubuntu 13.04
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: sv3tli0 at bgspot dot eu
New email:
PHP Version: OS:

 

 [2013-09-09 07:35 UTC] sv3tli0 at bgspot dot eu
Description:
------------
Wrong result if you are checking array for existing integer 0, when array has 
none integer values.. 

Test script:
---------------
$array = array(1,2,3);
var_dump(in_array(0, $array)); 

$array = array(1,2,'some string not INT');
var_dump(in_array(0, $array)); 



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

boolean false

Actual result:
--------------
boolean false

boolean true

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-09-09 08:35 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2013-09-09 08:35 UTC] requinix@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

in_array() does a loose comparison by default, and 0 == 'some string not INT'.
If you need a strict comparison then pass true for the third argument.

http://www.php.net/in-array
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri May 02 10:01:28 2025 UTC