Req->Bug #79583 [Opn->Nab]: Bug? in array_search
| From: | requinix@php.net | Date: | Mon, 11 May 2020 06:17:55 +0000 |
| Subject: | Req->Bug #79583 [Opn->Nab]: Bug? in array_search | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-226986@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79583&edit=1
ID: 79583
Updated by: requinix@php.net
Reported by: yattyan83 at gmail dot com
Summary: Bug? in array_search
-Status: Open
+Status: Not a bug
-Type: Feature/Change Request
+Type: Bug
Package: Arrays related
Operating System: Windows 64bit/Linux aa4240282e4d
PHP Version: 7.3.17
Block user comment: N
Private report: N
New Comment:
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
array_search() checks for loose equality by default, and 0 == null.
Use the $strict parameter.
Previous Comments:
------------------------------------------------------------------------
[2020-05-11 06:14:45] yattyan83 at gmail dot com
Description:
------------
---
From manual page: https://php.net/function.array-search
---
I used array_search() to look at the beginning of the array and find the location of the first
null.ï¼In order to fill the array's nulls per requestï¼
But array_search() tests 0 as null.
Try the example below.
Test script:
---------------
$array = [
'a' => 1,
'b' => 0,
'c' => null,
'd' => null
];
echo array_search(null, $array);//expect c
> b
Expected result:
----------------
I would have liked to have gotten a C back if I could.
You can also use foreach as an alternative, so please let me know if this is a spec or a bug.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79583&edit=1