php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39153 array_search and in_array return unexpected values
Submitted: 2006-10-13 22:14 UTC Modified: 2006-10-13 22:23 UTC
From: jasonp at quadco dot net Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.1.6 OS: Linux 2.6.18
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: jasonp at quadco dot net
New email:
PHP Version: OS:

 

 [2006-10-13 22:14 UTC] jasonp at quadco dot net
Description:
------------
If int 0 is used as an array_search or in_array needle and int 
0 is not an element in the haystack, array_search and in_array 
will return int 0 and boolean true, respectively, instead of 
boolean false as expected.

Reproduce code:
---------------
$array = array('x', 'y', 'z');

var_dump(array_search(0, $array));
var_dump(in_array(0, $array));

Expected result:
----------------
var_dump and in_array should have spit out boolean(false) 
since int 0 is not in array $array.

Actual result:
--------------
int(0) bool(true)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-13 22:23 UTC] tony2001@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

var_dump((int)'x');
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 05:00:01 2026 UTC