Bug #65844 [Opn->Nab]: array_search returns wrong last key if value it is 0
| From: | nikic@php.net | Date: | Sun, 06 Oct 2013 11:10:02 +0000 |
| Subject: | Bug #65844 [Opn->Nab]: array_search returns wrong last key if value it is 0 | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-182057@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=65844&edit=1
ID: 65844
Updated by: nikic@php.net
Reported by: marc-bennewitz at arcor dot de
Summary: array_search returns wrong last key if value it is 0
-Status: Open
+Status: Not a bug
Type: Bug
Package: Arrays related
Operating System: linux
PHP Version: 5.5.4
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2013-10-06 11:01:00] 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"
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=65844&edit=1