|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #60485 in_array insensitive string comparison
Submitted: 2011-12-09 16:48 UTC Modified: -
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: Hast4656 at gmail dot com Assigned:
Status: Open Package: Arrays related
PHP Version: Irrelevant OS: linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2011-12-09 16:48 UTC] Hast4656 at gmail dot com
Can you please add parameter for in_array that let this function to compare 
strings insensitive?

Test script:
// something like
in_array('a', Array('a', 'A'), true, true);

// 4th bool param says should the function compare string in a case-sensitive manner or not


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-12-14 18:01 UTC]
Since in_array() handles different types, I don't think it would make sense to 
add a parameter that is exclusive to handling strings.
 [2011-12-30 04:19 UTC] phristen at yahoo dot com
How about adding a comparitor callback then?
Maybe even overload the third argument (e.g. if it's not a boolean, then assume callback), so we can do something like:

in_array('a', array('A', 'b'), function($a, $b) { return !strcasecmp($a, $b); });
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Apr 16 00:01:23 2021 UTC