|  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: 2021-06-25 11:56 UTC
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: cmb (profile)
Status: Wont fix Package: Arrays related
PHP Version: Irrelevant OS: linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: Hast4656 at gmail dot com
New email:
PHP Version: OS:


 [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); });
 [2021-06-25 11:56 UTC]
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: cmb
 [2021-06-25 11:56 UTC]
This is unlikely to be implemented; a more general solution, i.e.
a function any() or some() has a better chance, but still would
need an RFC[1].

[1] <>
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jul 19 15:01:28 2024 UTC