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
 [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-2022 The PHP Group
All rights reserved.
Last updated: Fri May 27 12:07:03 2022 UTC