php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65844 array_search returns wrong last key if value it is 0
Submitted: 2013-10-06 11:01 UTC Modified: 2013-10-06 11:10 UTC
From: marc-bennewitz at arcor dot de Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.5.4 OS: linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: marc-bennewitz at arcor dot de
New email:
PHP Version: OS:

 

 [2013-10-06 11:01 UTC] marc-bennewitz at arcor dot de
Description:
------------
array_search returns wrong last key (instead of false) if value it is 0

Test script:
---------------
$arr = array(
  "ONE"=>1,
  "TWO"=>2,
  "THREE"=>3,
  "FOUR"=>4,
  "FIVE"=>5,
  "SIX"=>6,
  "SEVEN"=>7,
  "EIGHT"=>8,
  "NINE"=>9,
  "ZERO"=>0
);
var_dump(array_search('unknown', $arr));

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

Actual result:
--------------
string(4) "ZERO"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-10-06 11:10 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2013-10-06 11:10 UTC] nikic@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

0 == 'unknown', so that's the element that will be found. If you want to use === comparison pass the $strict=true parameter.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jan 09 03:01:28 2025 UTC