Bug #70798 [Nab]: array_search - positive match on $haystack[0] evalutes to boolean FALSE

From: Date: Tue, 27 Oct 2015 01:49:02 +0000
Subject: Bug #70798 [Nab]: array_search - positive match on $haystack[0] evalutes to boolean FALSE
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-196835@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70798&edit=1 ID: 70798 User updated by: andreas dot baumgaertner at tisco dot at Reported by: andreas dot baumgaertner at tisco dot at Summary: array_search - positive match on $haystack[0] evalutes to boolean FALSE Status: Not a bug Type: Bug Package: *General Issues Operating System: Windows Server 2012 R2 PHP Version: 5.6.14 Block user comment: N Private report: N New Comment: I've read the documentation array_search ... Returns the key for needle if it is found in the array, FALSE otherwise. The issue is that the function returns FALSE instead of the key, when the match is at integer index [0]. I can't make the test script any shorter to proove my point. The test script does a simple case insensitve compare using array_map / strtolower and array_search ... -- I've taken the time to create the bug - at least take the time to run the test script! Previous Comments: ------------------------------------------------------------------------ [2015-10-27 01:24:29] 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 http://php.net/manual/en/function.array-search.php > Warning: This function may return Boolean FALSE, but may also return a non- > Boolean value which evaluates to FALSE. Please read the section on Booleans for > more information. Use the === operator for testing the return value of this > function. ------------------------------------------------------------------------ [2015-10-27 01:03:52] andreas dot baumgaertner at tisco dot at Description: ------------ array_search - positive match on $haystack[0] evalutes to boolean FALSE the same value at integer array index 1 matches perfectly and evaluates to 1 -- change sample script to $haystack[1] = 'German'; $haystack[2] = 'English'; array_search('german',$haystack_lower) returns 1 now ... Test script: --------------- <?php $haystack = array(); $haystack[0] = 'German'; $haystack[1] = 'English'; $haystack_lower = array_map('strtolower', $haystack); print_r($haystack); print_r('<br>'); print_r($haystack_lower); print_r('<br>'); if (array_search('german',$haystack_lower) != FALSE) { print_r('match'); } ?> ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=70798&edit=1

« previous php.bugs (#196835) next »