Bug #79583 [Com]: Bug? in array_search

From: Date: Mon, 11 May 2020 07:06:02 +0000
Subject: Bug #79583 [Com]: Bug? in array_search
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226988@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 Comment by: bugreports at gmail dot com Reported by: yattyan83 at gmail dot com Summary: Bug? in array_search Status: Not a bug 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: what about use the third param and set it to TRUE to avoid type juggling Previous Comments: ------------------------------------------------------------------------ [2020-05-11 06:38:26] yattyan83 at gmail dot com I see, it was a lack of confirmation on my part. Using the $strict parameter worked well. Thank you very much. ------------------------------------------------------------------------ [2020-05-11 06:17:55] requinix@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 array_search() checks for loose equality by default, and 0 == null. Use the $strict parameter. ------------------------------------------------------------------------ [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

« previous php.bugs (#226988) next »