php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44213 in_array returns wrong value
Submitted: 2008-02-22 12:24 UTC Modified: 2008-02-22 12:37 UTC
From: markus dot kalkbrenner at arcor dot de Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.2.5 OS: Linux
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: markus dot kalkbrenner at arcor dot de
New email:
PHP Version: OS:

 

 [2008-02-22 12:24 UTC] markus dot kalkbrenner at arcor dot de
Description:
------------
in_array() returns true if needle exists as key with int(0) as value, but should return false because needle doesn't exist as value.

Reproduce code:
---------------
<?php
var_dump( in_array('a', array('a' => 1) ) );
var_dump( in_array('a', array('a' => 0) ) );
?>

Expected result:
----------------
bool(false)
bool(false)


Actual result:
--------------
bool(false)
bool(true)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-02-22 12:37 UTC] felipe@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

This result is expected.

In "a" == 0, "a" is converted to int. For strict comparison, use the third parameter.

http://docs.php.net/in-array
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 04 20:01:35 2025 UTC