#39153 [Opn->Bgs]: array_search and in_array return unexpected values

From: Date: Fri, 13 Oct 2006 22:23:15 +0000
Subject: #39153 [Opn->Bgs]: array_search and in_array return unexpected values
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-103533@lists.php.net to get a copy of this message
ID: 39153 Updated by: tony2001@php.net Reported By: jasonp at quadco dot net -Status: Open +Status: Bogus Bug Type: Arrays related Operating System: Linux 2.6.18 PHP Version: 5.1.6 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 var_dump((int)'x'); Previous Comments: ------------------------------------------------------------------------ [2006-10-13 22:14:21] jasonp at quadco dot net Description: ------------ If int 0 is used as an array_search or in_array needle and int 0 is not an element in the haystack, array_search and in_array will return int 0 and boolean true, respectively, instead of boolean false as expected. Reproduce code: --------------- $array = array('x', 'y', 'z'); var_dump(array_search(0, $array)); var_dump(in_array(0, $array)); Expected result: ---------------- var_dump and in_array should have spit out boolean(false) since int 0 is not in array $array. Actual result: -------------- int(0) bool(true) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=39153&edit=1

« previous php.bugs (#103533) next »