php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80505 BUG
Submitted: 2020-12-11 12:38 UTC Modified: 2020-12-11 12:40 UTC
From: juergen dot wilmsmann at juergenwilmsmann dot de Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 7.4.13 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
2 + 28 = ?
Subscribe to this entry?

 
 [2020-12-11 12:38 UTC] juergen dot wilmsmann at juergenwilmsmann dot de
Description:
------------
---
From manual page: https://php.net/function.array-search
---
If in array integer 0 exists before the searched value exists, 
the search stopped by integer 0 and give as the result the key of integer 0.

Test script:
---------------
$arr[1] = "a";
$arr[2] = 0;
$arr[3] = "c";
$arr[4] = "d";
$key	= array_search("c", $arr);
//Result is 2	- !!! Wrong !!!
$arr[1] = "a";
$arr[2] = "";
$arr[3] = "c";
$arr[4] = "d";
$key	= array_search("c", $arr);
//Result is 3	- OK
$arr[1] = "a";
$arr[2] = "";
$arr[3] = "c";
$arr[4] = 0;
$key	= array_search("c", $arr);
//Result is 3 - OK


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-12-11 12:40 UTC] peehaa@php.net
-Status: Open +Status: Not a bug
 [2020-12-11 12:40 UTC] peehaa@php.net
For version < PHP 8 pass the strict argument to the function
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 12:01:27 2024 UTC