php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46365 bug in function array_search
Submitted: 2008-10-22 14:28 UTC Modified: 2008-10-22 21:00 UTC
From: spabox at hshhhhh dot name Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.2.6 OS: winxp
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: spabox at hshhhhh dot name
New email:
PHP Version: OS:

 

 [2008-10-22 14:28 UTC] spabox at hshhhhh dot name
Description:
------------
bug in function array_search:
when first element in array is zero, function return zero, but if null, false or sth else returning correct key.

Reproduce code:
---------------
$a = array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  'a');
var_dump($a);
var_dump(array_search('a', $a));

Expected result:
----------------
int(0)

Actual result:
--------------
int(1)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-10-22 14:32 UTC] spambox at hshhhhh dot name
in array_keys() bug too
$a = array(0, 'a','a');
var_dump(array_keys($a,'a'));


#array(3) {
#  [0]=>
#  int(0)
#  [1]=>
#  int(1)
#  [2]=>
#  int(2)
#}
 [2008-10-22 21:00 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

Hello, read about the third parameter. (bool $strict)

http://docs.php.net/array-search
http://docs.php.net/array-keys
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 01:01:31 2024 UTC