Bug #65900 [Opn->Nab]: array_search doesn't work with mixed array

From: Date: Tue, 15 Oct 2013 17:16:28 +0000
Subject: Bug #65900 [Opn->Nab]: array_search doesn't work with mixed array
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-182291@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=65900&edit=1 ID: 65900 Updated by: nikic@php.net Reported by: abhinavjpenmetsa at gmail dot com Summary: array_search doesn't work with mixed array -Status: Open +Status: Not a bug Type: Bug -Package: Output Control +Package: Arrays related Operating System: linux PHP Version: Irrelevant Block user comment: N Private report: N New Comment: Sorry, but your problem does not imply a bug in PHP itself. For a list of more appropriate places to ask for help using PHP, please visit http://www.php.net/support.php as this bug system is not the appropriate forum for asking support questions. Due to the volume of reports we can not explain in detail here why your report is not a bug. The support channels will be able to provide an explanation for you. Thank you for your interest in PHP. You have not specified the $strict parameter of array_search, so the comparison is done using ==. As 0 == 'green' that is the element that's found. If you want type-strict comparison pass true as the last parameter. Previous Comments: ------------------------------------------------------------------------ [2013-10-15 14:53:30] abhinavjpenmetsa at gmail dot com Description: ------------ --- From manual page: http://www.php.net/function.array-search#refsect1-function.array-search-returnvalues --- try the below code Test script: --------------- $array = array(5,0,'green',9); $needle = 'green'; var_dump(array_search($needle, $array)); Expected result: ---------------- int(2) Actual result: -------------- int(1) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=65900&edit=1

« previous php.bugs (#182291) next »